2012-04-19 06:32:10 +00:00
|
|
|
|
|
|
|
module Types where
|
|
|
|
|
|
|
|
import Data.List (intercalate)
|
2012-05-11 10:28:56 +00:00
|
|
|
import qualified Data.Set as Set
|
|
|
|
|
|
|
|
type X = Int
|
2012-04-19 06:32:10 +00:00
|
|
|
|
|
|
|
data Type = IntT
|
|
|
|
| StringT
|
|
|
|
| CharT
|
|
|
|
| BoolT
|
|
|
|
| LambdaT Type Type
|
2012-05-11 10:28:56 +00:00
|
|
|
| VarT X
|
2012-04-19 06:32:10 +00:00
|
|
|
| AppT String [Type]
|
|
|
|
| ADT String [Type]
|
2012-05-11 10:28:56 +00:00
|
|
|
deriving (Eq, Ord)
|
|
|
|
|
|
|
|
data Scheme = Forall (Set.Set X) Type deriving (Eq, Ord, Show)
|
2012-04-19 06:32:10 +00:00
|
|
|
|
|
|
|
data Constructor = Constructor String [Type] deriving (Eq, Show)
|
|
|
|
|
|
|
|
instance Show Type where
|
|
|
|
show t =
|
|
|
|
case t of
|
|
|
|
{ IntT -> "Int"
|
|
|
|
; StringT -> "String"
|
|
|
|
; CharT -> "Char"
|
|
|
|
; BoolT -> "Bool"
|
|
|
|
; LambdaT t1 t2 -> show t1 ++ " -> " ++ show t2
|
2012-05-11 10:28:56 +00:00
|
|
|
; VarT x -> show x
|
2012-04-28 07:26:46 +00:00
|
|
|
; AppT name args -> name ++ " " ++ unwords (map show args)
|
2012-05-11 10:28:56 +00:00
|
|
|
; ADT name constrs -> name
|
2012-04-19 06:32:10 +00:00
|
|
|
}
|