Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial dcbn

  • Loading branch information...
commit d1a530cc8aaa824ed5b722b585a00f3cb3316ec1 1 parent 071cb1e
Joe Pletcher authored
Showing with 9 additions and 7 deletions.
  1. +5 −5 3-dcbn.hs
  2. +2 −1  3-dcbv.hs
  3. +2 −1  3-scbv.hs
10 3-dcbn.hs
View
@@ -7,7 +7,7 @@ data Term = TmLet String Term Term
| TmFalse
| TmNat Int
| TmApply Term Term
- | TmLambda String Term Env
+ | TmLambda String Term
-- Static Call by Value
type Env = [(String, Term)]
@@ -28,13 +28,13 @@ eval (TmIf c t f) env = do c' <- eval c env
eval (TmApply f v) env = do
f' <- eval f env
- v' <- eval v env
case f' of
- TmLambda n body env' -> eval body (addEnv n v' env')
+ TmLambda n body -> eval body (addEnv n v env)
_ -> Nothing
eval (TmNat n) _ = return $ TmNat n
-eval (TmVar id) env = getEnv id env
-eval (TmLambda s t _) env = return $ TmLambda s t env
+eval (TmVar id) env = do v <- getEnv id env
+ eval v env
+eval (TmLambda s t) env = return $ TmLambda s t
eval TmTrue _ = return TmTrue
eval TmFalse _ = return TmFalse
3  3-dcbv.hs
View
@@ -19,7 +19,8 @@ getEnv :: String -> Env -> Maybe Term
getEnv k env = lookup k env
eval :: Term -> Env -> Maybe Term
-eval (TmLet k v t) env = eval t (addEnv k v env)
+eval (TmLet k v t) env = do v' <- eval v env
+ eval t (addEnv k v' env)
eval (TmIf c t f) env = do c' <- eval c env
case c' of
TmTrue -> eval t env
3  3-scbv.hs
View
@@ -19,7 +19,8 @@ getEnv :: String -> Env -> Maybe Term
getEnv k env = lookup k env
eval :: Term -> Env -> Maybe Term
-eval (TmLet k v t) env = eval t (addEnv k v env)
+eval (TmLet k v t) env = do k' <- eval k env
+ eval t (addEnv k' v env)
eval (TmIf c t f) env = do c' <- eval c env
case c' of
TmTrue -> eval t env
Please sign in to comment.
Something went wrong with that request. Please try again.