aboutsummaryrefslogtreecommitdiff
path: root/AST.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2021-11-20 08:54:46 +0100
committerTom Smeding <tom@tomsmeding.com>2021-11-20 08:54:46 +0100
commitd1cb805a26483cb64fea221cea4991c097f90fc0 (patch)
treee5bb93382d6d75e33064edb48179021ba8af8f9d /AST.hs
Initial WIP
Diffstat (limited to 'AST.hs')
-rw-r--r--AST.hs52
1 files changed, 52 insertions, 0 deletions
diff --git a/AST.hs b/AST.hs
new file mode 100644
index 0000000..f8f3624
--- /dev/null
+++ b/AST.hs
@@ -0,0 +1,52 @@
+module AST where
+
+
+data Program t = Program [FunDef t]
+ deriving (Show)
+
+data FunDef t = FunDef Name (Maybe Type) [FunEq t]
+ deriving (Show)
+
+newtype Name = Name String
+ deriving (Show)
+
+data Type
+ = TApp Name [Type]
+ | TTup [Type]
+ | TList Type
+ | TFun Type Type
+ deriving (Show)
+
+data FunEq t = FunEq Name [Pattern t] (RHS t)
+ deriving (Show)
+
+data Pattern t
+ = PWildcard t
+ | PVar t Name
+ | PAs t Name (Pattern t)
+ | PCon t Name [Pattern t]
+ | PList t [Pattern t]
+ | PTup t [Pattern t]
+ deriving (Show)
+
+data RHS t
+ = Guarded [(Expr t, Expr t)]
+ | Plain (Expr t)
+ deriving (Show)
+
+data Expr t
+ = ELit t Literal
+ | EList t [Expr t]
+ | ETup t [Expr t]
+ | EApp t (Expr t) (Expr t)
+ | EOp t (Expr t) Operator (Expr t)
+ | EIf t (Expr t) (Expr t) (Expr t)
+ | ECase t (Expr t) [(Pattern t, RHS t)]
+ | ELet t [FunDef t] (Expr t)
+ deriving (Show)
+
+data Literal = LInt Int | LFloat Double | LChar Char | LString String
+ deriving (Show)
+
+data Operator = OAdd | OSub | OMul | ODiv | OMod
+ deriving (Show)