-
Notifications
You must be signed in to change notification settings - Fork 0
/
Head.hs
48 lines (41 loc) · 1.28 KB
/
Head.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Head where
type Index = Int
type Id = String
data TI a = TI (Index -> (a, Index))
type Subst = [(Id, SimpleType)]
data Type = Forall SimpleType deriving (Eq, Show)
data Assump = Id :>: Type deriving (Eq, Show)
data Literal = Int | Bool | TInt Int | TBool Bool deriving (Eq)
data SimpleType = TVar Id
| TArr SimpleType SimpleType
| TLit Literal
| TCon Id
| TApp SimpleType SimpleType
| TGen Int
deriving Eq
data Pat = PVar Id
| PLit Literal
| PCon Id [Pat]
deriving (Eq, Show)
data Expr = Var Id
| App Expr Expr
| Lam Id Expr
| Lit Literal
| Con Id
| If Expr Expr Expr
| Case Expr [(Pat,Expr)]
| Let (Id,Expr) Expr
deriving (Eq, Show)
instance Show SimpleType where
show (TVar i) = i
show (TArr (TArr a b) t') = "("++show (TArr a b)++")"++"->"++show t'
show (TArr t t') = show t++"->"++show t'
show (TCon i) = i
show (TApp c v) = show c ++ " " ++ show v
show (TLit tipo) = show tipo
show (TGen n) = "tg" ++ show n
instance Show Literal where
show (TInt _) = "Int"
show (TBool _) = "Bool"
show Int = "Int"
show Bool = "Bool"