rescript-lang / rescript

ReScript is a robustly typed language that compiles to efficient and human-readable JavaScript.
https://rescript-lang.org
Other
6.77k stars 453 forks source link

Uncurried mode doesn't propagate to built-in stdlibs. #6147

Closed DZakh closed 2 months ago

DZakh commented 1 year ago

I have the rule to add a type definition when I use Obj.magic for casting types. In this case, it becomes more explicit, and the compiler at least can check that input and output types are used correctly. How can I do the same in the uncurried mode? Looks like the uncurried: true doesn't propagate to the built-in stdlibs.

image
cristianoc commented 1 year ago

It should propagate to pervasives.

At the moment trying not to make 2 copies of everything. So perhaps it's just that Obj.magic is not in pervasives. In this case: let magic = x => magic(x) should do.

Later on, we can assess how many things we want 2 copies of. Note, if one uses things from Core being it an external library, it will be compiled in uncurried mode. So we might do nothing about stuff in built-in libs which is also present in Core.

cristianoc commented 1 year ago

OK so if you look into node_modules/rescript/lib/ocaml, the only one for which we do 2 copies at the moment is pervasives. Notice that most of the time it just works. So go ahead and use Obj.magic. Just don't write a type annotation for it. Or eta-expand it as in my previous response.

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.