Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining ocaml primitives of type tuple #106

Open
thelogicalgrammar opened this issue Oct 29, 2022 · 1 comment
Open

Defining ocaml primitives of type tuple #106

thelogicalgrammar opened this issue Oct 29, 2022 · 1 comment

Comments

@thelogicalgrammar
Copy link

thelogicalgrammar commented Oct 29, 2022

If I understand correctly, the situation is the following. To define new domains, we sometimes have to define new primitives in ocaml, which means we have to define their types. However, we can't use ocaml's typing system directly, but rather we have to define types with dreamcoder's typing system. Dreamcoder's types (in ocaml) are objects of type tp. Tp is a sum type, with two kinds of elements, TID (for type variables) and TCon (for all other types). Each TCon object then is a tuple with three elements:

  1. The name of the primitive
  2. A (possibly empty) list of the types of the arguments to that primitive
  3. A boolean, specifying recursively whether any of the arguments is a type variable

For instance, the tlist type is defined as

let tlist t = TCon("list",[t], ts |> List.exists ~f:is_polymorphic);;

and the type of a function from int to int is defined as

let tint = TCon('int',[],false);;
let tintintf = TCon('intintf',[tint;tint],false);;

What I am wondering is whether it would be possible to implement a tuple type, e.g. as:

let ttuple t1 t2 = TCon('tuple',[t1*t2],  [t1;t2] |> List.exists ~f:is_polymorphic);;
let ttriple t1 t2 t3 = TCon('tuple',[t1*t2*t3], [t1;t2;t3] |> List.exists ~f:is_polymorphic);;

and how would we use it to construct primitives and how it would interface with python primitives.

@DanieleMarchei
Copy link

I stumbled upon this line of code while reading type.py

def tpair(a, b): return TypeConstructor("pair", [a, b])

I guess pairs are already defined, and I think they are easily extensible too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants