84 lines
1.3 KiB
Plaintext
84 lines
1.3 KiB
Plaintext
// Comment!
|
|
|
|
type SimpleType
|
|
= MyVariant1
|
|
| MyVariant2 Int[u32]
|
|
| MyVariant3 Int[1..20]
|
|
| MyVariant4 Int String
|
|
|
|
/* Multiline
|
|
Comment! */
|
|
|
|
type Option val
|
|
= Some val
|
|
| None
|
|
|
|
struct MyStruct =
|
|
.field1 : SimpleType
|
|
.field2 : Int
|
|
|
|
trait Eq needs
|
|
.add : Self, Self -> Self
|
|
|
|
trait Functor[a, b] on Self _ needs
|
|
.map : (a -> b), Self a -> Self b
|
|
.pure : a -> Self a
|
|
|
|
type ComplexType a b[Functor]
|
|
= Left a
|
|
Right b
|
|
|
|
impl Functor on Option _:
|
|
.map mapper union = if union is
|
|
Some val -> Some (mapper val)
|
|
None -> None
|
|
.pure elem = Some elem
|
|
|
|
magnitude : Int, Int -> Int
|
|
magnitude x y = sqrt (x * x) (y * y)
|
|
|
|
soundeffect : Bool -> Str
|
|
soundeffect type =
|
|
if type then
|
|
"bip!"
|
|
else
|
|
"bop!"
|
|
|
|
destructure : MyStruct -> Option Int
|
|
destructure s =
|
|
if s is
|
|
MyStruct
|
|
.field1 = MyVariant2 a
|
|
.field2 = 0
|
|
-> Some (magnitude a 10)
|
|
MyStruct
|
|
.field1 = MyVariant1
|
|
.field2
|
|
->
|
|
if a > 10
|
|
Some a
|
|
else
|
|
None
|
|
_ -> None
|
|
|
|
destructure_type : SimpleType -> Int
|
|
destructure_type t =
|
|
if t is
|
|
MyVariant1 -> 0
|
|
MyVariant2 x -> x * x
|
|
MyVariant3 x -> x /2
|
|
MyVariant4 x _ -> x
|
|
|
|
simple_tuple : (Int, Int)
|
|
simple_tuple = (1, 2)
|
|
|
|
magnitude_plus_ten : Int, Int -> Int
|
|
magnitude_plus_ten x y =
|
|
let magnitude =
|
|
let x_squared = x * x
|
|
let y_squared = y * y
|
|
in sqrt (x + y)
|
|
in
|
|
let magnitude_plus_5 = magnitude + 5
|
|
in magnitude_plus_5 + 5
|