diff options
author | Camil Staps | 2023-01-23 15:08:24 +0100 |
---|---|---|
committer | Camil Staps | 2023-01-23 15:08:24 +0100 |
commit | 91b21db725540043640edda6f28b798f4ffcb7c5 (patch) | |
tree | 8643902166762d426fb0ef2bfc33aa6eb0cc7292 /example.txt | |
parent | Initial commit (diff) |
Add example of small functional language and run time system
Diffstat (limited to 'example.txt')
-rw-r--r-- | example.txt | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/example.txt b/example.txt new file mode 100644 index 0000000..b83c606 --- /dev/null +++ b/example.txt @@ -0,0 +1,66 @@ +(data (Tuple a b) + (Tuple a b)) +(data (List a) + Nil + (Cons a (List a))) +(type String (List Char)) + +(fun readline : (List Char) + (case getc + '\n' -> Nil + c -> c : readline)) + +(fun length (xs : (List a)) : Int + (length_acc 0 xs)) +(fun length_acc (n : Int) (xs : (List a)) : Int + (case xs + Nil -> n + Cons _ xs -> length_acc (+ n 1) xs)) + +(data Type + (Type String) + (TypeVar String) + (TypeApp Type Type)) + +(data ConstructorDef + (ConstructorDef String (List Type))) + +(data BasicValue + (BVInt Int) + (BVChar Char)) + +(data Pattern + WildCard + (BasicValuePattern BasicValue) + (IdentPattern String) + (ConstructorPattern String (List Pattern))) + +(data CaseAlternative + (CaseAlternative Pattern Expression)) + +(data Expression + (Ident String) + (Case Expression (List CaseAlternative)) + (ExpApp Expression Expression)) + +(data Definition + (DataDef String (List String) (List ConstructorDef)) + (FunDef String (List (Tuple String Type)) Type Expression)) + +(fun list_ast : Definition + (DataDef + (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil)))) + (Cons (Cons 'a' Nil) Nil) + (Cons (ConstructorDef (Cons 'N' (Cons 'i' (Cons 'l' Nil))) Nil) + (Cons (ConstructorDef (Cons 'C' (Cons 'o' (Cons 'n' (Cons 's' Nil)))) (Cons (TypeVar (Cons 'a' Nil)) (Cons (TypeApp (Type (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil))))) (TypeVar (Cons 'a' Nil))) Nil))) + Nil)))) +(fun length_acc_ast : Definition + (FunDef + (Cons 'l' (Cons 'e' (Cons 'n' (Cons 'g' (Cons 't' (Cons 'h' (Cons '_' (Cons 'a' (Cons 'c' (Cons 'c' Nil)))))))))) + (Cons (Tuple (Cons 'n' Nil) (Type (Cons 'I' (Cons 'n' (Cons 't' Nil))))) + (Cons (Tuple (Cons 'x' (Cons 's' Nil)) (TypeApp (Type (Cons 'L' (Cons 'i' (Cons 's' (Cons 't' Nil))))) (TypeVar (Cons 'a' Nil)))) + Nil)) + (Case (Ident (Cons 'x' (Cons 's' Nil))) + (Cons (CaseAlternative (ConstructorPattern (Cons 'N' (Cons 'i' (Cons 'l' Nil))) Nil) (Ident (Cons 'n' Nil))) + (Cons (CaseAlternative (ConstructorPattern (Cons 'C' (Cons 'o' (Cons 'n' (Cons 's' Nil)))) (Cons WildCard (Cons (IdentPattern (Cons 'x' (Cons 's' Nil))) Nil))) ()) + Nil))))) |