tweag / nickel

Better configuration for less
https://nickel-lang.org/
MIT License
2.23k stars 85 forks source link

Do not evaluate types away #1954

Closed yannham closed 3 weeks ago

yannham commented 3 weeks ago

Before this change, types used in a term would be evaluated away to their corresponding contract (a function) automatically. Note that the only meaningful usage of types right now is to pass them as argument for std.contract.apply.

This eager conversion loses information; either for error messages (for example, using a type in the wrong place will complain that something has type "function" and might point to inside Nickel internals instead of the actual user-written type). Moreover, in preparation for boolean combinators for contracts, we want to be able to remember the original form of a type as much as possible.

Finally, it might be useful for users to introspect types as well, for example to implement custom contract combinators.

For all these reasons, and because there's no apparent drawback, this commit makes type normal values, that aren't evaluated further. A new case in the %contrat/apply% primop simply performs the conversion to contract lazily, once they are actually applied, instead of where they are defined. %typeof% and std.typeof are updated accordingly with the new 'Type tag.

Related: #1466, #1460