zilch-lang/nstar

Type aliases

Opened this issue · 0 comments

Sometimes, writing some code yields very complicated types (we can see some of them in the test codes⁽¹⁾).
Those types are hard to write, hard to read, and you probably never write them only once.

We propose to introduce type aliases, using a special construct such as type TypeName<typeParams...> = <type> where typeParams... are type variables annotated with their kinds (as in the forall construct for label types).
This construct allows to reuse types while giving them a more semantically correct name. It also reduces the cost associated with refactoring when, for example, we change the return type of a function and add another register.
And this has no runtime cost, since all types are erased.


⁽¹⁾ https://github.com/zilch-lang/nsc/blob/4c1fcc20dcaef6aebb3fe0c2532722efdda5da58/test/error_tc_popCodeAddressFromStack.nst#L1-L22