mirror of
https://github.com/swarm-game/swarm.git
synced 2024-10-27 01:49:15 +03:00
01c45ab968
Adds type synonym declarations to the language, like so: ``` tydef Maybe a = Unit + a end def lookdown : Cmd (Maybe Text) = scan down end > lookdown it2 : Maybe Text = inl () ``` `tydef` behaves very similarly to `def` except that it defines a new (parameterized) type instead of a new term. Note that higher-kinded types are not yet supported; for example we cannot say `tydef Foo f = Unit + f Int` (in fact this would be a syntax error since type variables cannot be at the head of an application). However there is nothing stopping us from adding that in the future; I just wanted to keep things simple for now. If you know of any scenario code that would be a good candidate for using type synonyms, let me know --- it would be nice to update a few scenarios as a better stress test of type synonyms before merging this. Closes #153.
10 lines
175 B
Plaintext
10 lines
175 B
Plaintext
tydef Maybe a = Unit + a end
|
|
|
|
def just : a -> Maybe a = inr end
|
|
|
|
def nothing : Maybe a = inl () end
|
|
|
|
def positive : Int -> Maybe Int = \x.
|
|
if (x > 0) {just x} {nothing}
|
|
end
|