25.10.2015 Views

Write You a Haskell Stephen Diehl

1kEcQTb

1kEcQTb

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

data Type<br />

= TVar Loc TVar<br />

| TCon Loc Name<br />

| TArr Loc Type Type<br />

deriving (Show, Eq, Ord)<br />

newtype TVar = TV String<br />

deriving (Show, Eq, Ord)<br />

typeInt :: Type<br />

typeInt = TCon NoLoc ”Int”<br />

setLoc :: Loc -> Type -> Type<br />

setLoc l (TVar _ a) = TVar l a<br />

setLoc l (TCon _ a) = TCon l a<br />

setLoc l (TArr _ a b) = TArr l a b<br />

getLoc :: Type -> Loc<br />

getLoc (TVar l _) = l<br />

getLoc (TCon l _) = l<br />

getLoc (TArr l _ _) = l<br />

Our fresh variable supply now also takes a location field which is attached to resulting type variable.<br />

fresh :: Loc -> Check Type<br />

fresh l = do<br />

s Check Type<br />

infer expr = case expr of<br />

Var l n -> do<br />

t do<br />

ta

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!