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.

Lit (LInt _) -> return (nullSubst, typeInt)<br />

Lit (LBool _) -> return (nullSubst, typeBool)<br />

Let’s walk through each of the rule derivations and look how it translates into code:<br />

T-Var<br />

e T-Var rule, simply pull the type of the variable out of the typing context.<br />

Var x -> lookupEnv env x<br />

e function lookupVar looks up the local variable reference in typing environment and if found it<br />

instantiates a fresh copy.<br />

lookupEnv :: TypeEnv -> Var -> Infer (Subst, Type)<br />

lookupEnv (TypeEnv env) x = do<br />

case Map.lookup x env of<br />

Nothing -> throwError $ UnboundVariable (show x)<br />

Just s -> do t do<br />

tv

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

Saved successfully!

Ooh no, something went wrong!