Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Confusion regarding generic type function definition inside of another function

$
0
0

I don’t see how it’s inconsistent. Types are inferred to be as general as possible given the constraints. At the top-level, there are no constraints and the most general type is polymorphic. As an inner function where you explicitly constrain it by assigning a type variable that is scoped to the outer function, it can only be generalized outside that scope. On the inside, the type variable needs to refer to a single concrete type across the entire scope. Otherwise it wouldn’t be sound.

You can of course disagree with the scoping rules. It would certainly be feasible to have type variables scoped to where it first appears. for example. But that would mean that type variables could change their scope, and therefore their meaning, if the same name is used in an outer scope. Personally, I don’t see that being a better solution.


Viewing all articles
Browse latest Browse all 2592

Trending Articles