Skip to content

Commit

Permalink
Clean up code.
Browse files Browse the repository at this point in the history
* src/Interpreter.hs (show :: Context -> String): Delete obsolete
  function.
  (lambdaEval): Use pattern matching instead of 'if'.
  • Loading branch information
Cyrill Schenkel committed Nov 24, 2016
1 parent 774af22 commit 25deae8
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ data Context = Context {
evalStrategy :: Strategy,
environment :: Environment}

instance Show Context where
show context = show $ Map.assocs $ environment context

bind :: Context -> String -> LambdaTerm -> Context
bind context var value =
context {environment = Map.insert var value $ environment context}
Expand All @@ -42,15 +39,13 @@ varLookup context var = case Map.lookup var $ environment context of
emptyEnvironment = Map.empty

lambdaEval :: Context -> LambdaTerm -> (Context, LambdaTerm)
lambdaEval context@Context {evalStrategy = Strategy {evalBodies = evalBodies}}
lambdaEval context@Context {evalStrategy = Strategy {evalBodies = True}}
l@(Lambda parameter term) =
if evalBodies
then
let (context', term') = lambdaEval context term in
(context', Lambda parameter term')
else
(context, l)
lambdaEval context a@(Application function argument) =
let (context', term') = lambdaEval context term in
(context', Lambda parameter term')
lambdaEval context@Context {evalStrategy = Strategy {evalBodies = False}}
l@(Lambda parameter term) = (context, l)
lambdaEval context (Application function argument) =
lambdaApply context function argument
lambdaEval context (Variable var) =
case varLookup context var of
Expand Down

0 comments on commit 25deae8

Please sign in to comment.