diff options
author | Tom Smeding <tom@tomsmeding.com> | 2024-02-17 09:22:49 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2024-02-17 09:22:49 +0100 |
commit | 3faca807fe96f2cefa50023fe373d8bcf1430121 (patch) | |
tree | 00ee8524bb93fb589468edea0502e626f7ff3df2 /src/AST.hs | |
parent | 3ef786673ff8298124cd3b5ef50c35dbb23f77e2 (diff) |
Move to src/, working HLS in examples/
Diffstat (limited to 'src/AST.hs')
-rw-r--r-- | src/AST.hs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/AST.hs b/src/AST.hs new file mode 100644 index 0000000..47652b6 --- /dev/null +++ b/src/AST.hs @@ -0,0 +1,61 @@ +module AST where + +import Data.List.NonEmpty (NonEmpty) + + +newtype Name = Name String + deriving (Show, Eq) + +data Program t = Program [DataDef] [FunDef t] + deriving (Show) + +data DataDef = DataDef Name [Name] [(Name, [Type])] + deriving (Show) + +data FunDef t = FunDef Name (Maybe Type) (NonEmpty (FunEq t)) + deriving (Show) + +data FunEq t = FunEq Name [Pattern t] (RHS t) + deriving (Show) + +data Type + = TApp Type [Type] + | TTup [Type] + | TList Type + | TFun Type Type + | TCon Name + | TVar Name + 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)] -- currently not parsed + | Plain (Expr t) + deriving (Show) + +data Expr t + = ELit t Literal + | EVar t Name + | ECon t Name + | 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 Integer | LFloat Rational | LChar Char | LString String + deriving (Show) + +data Operator = OAdd | OSub | OMul | ODiv | OMod | OEqu | OPow + deriving (Show) |