Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
force :: IORef Thunk -> IO Value<br />
force ref = do<br />
th Expr -> (Thunk -> IO Value)<br />
mkThunk env x body = \a -> do<br />
a’ Expr -> IO Value<br />
eval env ex = case ex of<br />
EVar n -> do<br />
th do<br />
VClosure c eval env b)<br />
EBool b -> return $ VBool b<br />
EInt n -> return $ VInt n<br />
EFix e -> eval env (EApp e (EFix e))<br />
For example, in this model the following program will not diverge since the omega combinator passed<br />
into the constant function is not used and therefore the argument is not evaluated.<br />
omega = (\x -> x x) (\x -> x x)<br />
test1 = (\y -> 42) omega<br />
omega :: Expr<br />
omega = EApp (ELam ”x” (EApp (EVar ”x”) (EVar ”x”)))<br />
(ELam ”x” (EApp (EVar ”x”) (EVar ”x”)))<br />
test1 :: IO Value<br />
test1 = eval [] $ EApp (ELam ”y” (EInt 42)) omega<br />
Higher Order Abstract Syntax (HOAS)<br />
GHC <strong>Haskell</strong> being a rich language has a variety of extensions that, among other things, allow us to<br />
map lambda expressions in our defined language directly onto lambda expressions in <strong>Haskell</strong>. In this<br />
72