There are more types than just classes and kinds.
The kind Type can be implemented by anything defining the method has-instance?.
The colon :
is special syntax for using instanceof
.
Symbol.hasInstance
isn't yet implemented in any JS engine.When declaring a local, use :
to assert its type.
For function return types, write the type right after the \
.
The Str and Num builtins act like String
and Number
but recognize primitives instead of the rarely-used object versions. There's also Bool and Sym.
number->string = \:Str _:Num "#_" || This should fail number->string []
You can also use value:Type
(with no spaces) to call contains?
.
For just :Type
, the test is on _
. (This works great in case
expressions!)
. 1:Num . not 1:Str _ = "one" . not :Num . :Str
Pred-Type
Any predicate can become a Type.
name.
adds an object property equal to
the current name being assigned to, in this case "Three"
.
Three = new Pred-Type name. predicate. \_ =? _ 3 . 3:Three . 4:Three
prefix
Mason code often uses prefixes and suffixes to indicate type.
The compiler doesn't treat these specially. msl follows this convention, but you don't have to.
Looks like | Means |
?a | ? option |
$a | $ promise |
@a | @ collection |
a->b | Map from a to b |
a? | Bool |
An optional promise is ?$a
; a promise for an option is $?a
.
a!
indicates a function that performs some action rather than just returning a value.