Data Types
Here is how you would declare a new type Vehicle
, which can be either a Car
, Plane
, or Submarine
.
type Vehicle
= Car
| Plane
| Submarine
Type Parameters TODO
Union Types can be given parameters to allow them to wrap values. In the example below, the type Vehicle
has a Car
case that carries a value of type Int
.
type Vehicle
= Car Int
| Sled
This would mean that to create an instance of type Car
, you would need to provide it an instance of Int
:
Car 42
Variable Type Parameters TODO
Union Types can also be given variable type parameters to allow them to wrap generic values. In the example below, the type Option
has a Some
case that carries a value of type Int
.
type Option a
= Some a
| None
This would mean that if you wanted to create an instance of Option Int
, you could use any of the following expressions:
Some 42
None
Some 1337
Some 0
Similarly, if you wanted to create an instance of Option String
, you could use any of the following expressions:
Some "yolo"
None