Skip to content

Instantly share code, notes, and snippets.

Created October 29, 2013 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7222017 to your computer and use it in GitHub Desktop.
Save anonymous/7222017 to your computer and use it in GitHub Desktop.
destructive update extension, the horror!
evalThen :: Env a -> Lambda a -> (Maybe (Lambda a) -> b)
evalThen env (Var a) then = then $ M.lookup a env
evalThen env abs@(Abs {}) then = then $ Just abs
evalThen env (App fun arg) then = then $ case fun of
Abs id body -> evalThen env arg >>= \a -> evalThen (M.insert id a env) body
_ -> Nothing
evalThen env p@(Prim {}) = then $ Just p
eval env term = eval env term id
exec env term = eval env term (\x -> case x of
(Var a) -> alter (\y -> x) a env
_ -> env)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment