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

Safe and named fresh type variables #20

Closed
leostera opened this issue Oct 20, 2020 · 1 comment · Fixed by #38
Closed

Safe and named fresh type variables #20

leostera opened this issue Oct 20, 2020 · 1 comment · Fixed by #38
Labels
bug Something isn't working compiler Related to the OCaml to Erlang compiler good first issue Good for newcomers

Comments

@leostera
Copy link
Owner

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.

@leostera leostera added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed compiler Related to the OCaml to Erlang compiler labels Oct 20, 2020
@leostera leostera added this to the v0.1 milestone Oct 20, 2020
@leostera
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler Related to the OCaml to Erlang compiler good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant