on a587ff5 help sign in
elk/src/Types/Types.hs
34 lines 885 B history raw
2module Types where
4import Data.List (intercalate)
5import Data.IORef
6import System.IO.Unsafe
8data Type = IntT
9 | StringT
10 | CharT
11 | BoolT
12 | LambdaT Type Type
13 | VarT String
14 | ForallT String Type
15 | AppT String [Type]
16 | ADT String [Type]
17 deriving (Eq)
19data Constructor = Constructor String [Type] deriving (Eq, Show)
21instance Show Type where
22 show t =
23 case t of
24 { IntT -> "Int"
25 ; StringT -> "String"
26 ; CharT -> "Char"
27 ; BoolT -> "Bool"
28 ; LambdaT t1 t2 -> show t1 ++ " -> " ++ show t2
29 ; VarT x -> x
30 ; ForallT x t' -> "forall " ++ x ++ ". " ++ show t'
31 ; AppT name args -> name ++ " " ++ intercalate " " (map show args)
32 ; ADT name constrs ->
33 name ++ " = " ++ intercalate " | " (map show constrs)
34 }