commit 3d1a7a6c6df5fc08090f8a1ff008aef95d969510 Author: Emi Simpson Date: Wed Mar 9 20:16:15 2022 -0500 Added a sample language file diff --git a/sample.amo b/sample.amo new file mode 100644 index 0000000..7fd6e28 --- /dev/null +++ b/sample.amo @@ -0,0 +1,64 @@ +union SimpleType + = MyVariant1 + | MyVariant2 Integer[u32] + | MyVariant3 Integer[1..20] + | MyVariant4 Integer String + +union Option val + = Some val + | None + +struct MyStruct = + .field1 : SimpleType + .field2 : Integer + +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 + +union 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 + +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 Integer +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 -> Integer +destructure_type t = + if t is + MyVariant1 -> 0 + MyVariant2 x -> x * x + MyVariant3 x -> x /2 + MyVariant4 x _ -> x