on ea05fbe help sign in
elk/src/Ast.hs
39 lines 990 B history raw
2module Ast where
4data Pattern = PData String [Pattern] | PVar String | PAnything
5 deriving (Show, Eq)
7data Expr = Number Int
8 | Chr Char
9 | Str String
10 | Boolean Bool
11 | Range Expr Expr
12 | Access Expr String
13 | Binop String Expr Expr
14 | Lambda String Expr
15 | App Expr Expr
16 | If Expr Expr Expr
17 | Lift Expr [Expr]
18 | Fold Expr Expr Expr
19 | Async Expr
20 | Input String
21 | Let [(String,Expr)] Expr
22 | Var String
23 | Case Expr [(Pattern,Expr)]
24 | Data String [Expr]
25 deriving (Show, Eq)
27cons h t = Data "Cons" [h,t]
28nil = Data "Nil" []
29list = foldr cons nil
30tuple es = Data ("Tuple" ++ show (length es)) es
32delist (Data "Cons" [h,t]) = h : delist t
33delist _ = []
36pcons h t = PData "Cons" [h,t]
37pnil = PData "Nil" []
38plist = foldr pcons pnil
39ptuple es = PData ("Tuple" ++ show (length es)) es