Type Aliasing in Verse
Verse supports giving a type another name that can be used to refer to the same underlying type. This is known as a type alias. The syntax is similar to constant initialization as it is basically the same thing, but using types instead of values.
For example, to give an alias to float the following syntax could be used:
number := float
Copy full snippet
You can use this to shorten some type signatures. For example, instead of the code below,
| | |
| --- | --- |
| | RotateInts(X : tuple(int, int, int)) : tuple(int, int, int) = |
| | ( X(3), X(1), X(2)) |
Copy full snippet
an alias could be introduced for tuple, like this:
| | |
| --- | --- |
| | int_triple := tuple(int, int, int) |
| | RotateInts(X : int_triple) : int_triple = |
| | (X(3), X(1), X(2)) |
Copy full snippet
This is particularly useful in combination with function types. For example,
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.