summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/src/Minilang/Lambda/Eval.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/Lambda/Eval.hs')
-rw-r--r--lambda-calcul/haskell/src/Minilang/Lambda/Eval.hs36
1 files changed, 7 insertions, 29 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/Lambda/Eval.hs b/lambda-calcul/haskell/src/Minilang/Lambda/Eval.hs
index cbbdc51..58f8ba6 100644
--- a/lambda-calcul/haskell/src/Minilang/Lambda/Eval.hs
+++ b/lambda-calcul/haskell/src/Minilang/Lambda/Eval.hs
@@ -9,36 +9,14 @@ data Term
| App Term Term
deriving (Show, Read, Eq)
-type Env = [(Text, Value)]
+type Env = [(Text, Term)]
-data Value
- = V Text
- | Abs Text Term Env -- a closure, ie. lambda with its captured environment
- | Ap Value Value
- deriving (Show, Read, Eq)
+newEnv :: Env
+newEnv = []
-- call-by-value evaluator
-eval :: Term -> Env -> Value
-eval (Var x) env = case lookup x env of
- Just v -> v -- we do not need to eval v again
- Nothing -> V x -- x is not bound in env
-eval (Lam x body) env = Abs x body env
-eval (App f a) env =
- -- we need to force evaluation of the argument
- -- because haskell's default semantics is non-strict
- -- so if a' is never used, it will not be evaluated!
- let a' = eval a env
- in seq a' $ case eval f env of
- Abs x body env' -> eval body ((x, a') : env')
- f' -> Ap f' a'
+eval :: Term -> Env -> Term
+eval = undefined
-evalNeed :: Term -> Env -> Value
-evalNeed (Var x) env = case lookup x env of
- Just v -> v
- Nothing -> V x
-evalNeed (Lam x body) env = Abs x body env
-evalNeed (App f a) env =
- let a' = eval a env
- in case evalNeed f env of
- Abs x body env' -> evalNeed body ((x, a') : env')
- f' -> Ap f' a'
+evalNeed :: Term -> Env -> Term
+evalNeed = undefined