leostera / caramel

:candy: a functional language for building type-safe, scalable, and maintainable applications

Home Page:https://caramel.run

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Safe and named fresh type variables

leostera opened this issue · comments

In this commit: e916333 I've replaced all instances of fresh type variables with any, in an attempt to unblock #19 -- after all those type signatures are not necessary for the Erlang code to compile and execute.

However, I do want to have this feature available, but it has one problem: a signature like unit -> 'a is valid in OCaml, but fun( () -> A ) is not in Erlang.

Thus, to really fix this, the commit above should be reverted, and during translation time we should check if the fresh variable name is actually already bound before in the same type expression, or if it is the only instance of it.

If it is the only instance, then we can use any() instead.

To fix this, we should begin by applying this patch:

-    | Tvar None -> Type.any
+    | Tvar None -> Type.var (Name.var (Type_var_names.find type_expr))

At the end of this module we should map over the list of types and for every function type we should have a data structure with all the data we need in a fairly straightforward form:

Type_function { tyfun_args; tyfun_return; }

And if the return type is a type variable name that was not bound in the arguments, we can loosen it up with Type.any instead.

After some playing around, this actually won't work either. We can only have bound variables as direct function parameters. I'll need to think about what's useful here on the Erlang side.