Permalink
Browse files

simplify eval.

  • Loading branch information...
1 parent a487b85 commit ddcb9439a958ad7721c9dc20e4267194a385c73c @kazu-yamamoto committed May 24, 2010
Showing with 7 additions and 11 deletions.
  1. +7 −11 Eval.hs
View
18 Eval.hs
@@ -12,22 +12,18 @@ evaluate exp0 = eval exp0 empty
eval :: Exp -> Stack Exp -> Exp
eval (exp1 :. exp2) stack = eval exp1 $ push exp2 stack
-eval exp1 stack = exec stack exp1
-
-exec :: Stack Exp -> Exp -> Exp
-exec stack0 exp1
- | isEmpty stack0 = exp1
-exec stack0 exp1@(Var _) = foldl (:.) exp1 $ map evaluate stack0
-exec stack0 S = eval (x :. z :. (y :. z)) stack3
+eval exp1 stack
+ | isEmpty stack = exp1
+eval exp1@(Var _) stack = foldl (:.) exp1 $ map evaluate stack
+eval S stack = eval (x :. z :. (y :. z)) stack3
where
- (x,stack1) = pop stack0
+ (x,stack1) = pop stack
(y,stack2) = pop stack1
(z,stack3) = pop stack2
-exec stack0 K = eval x stack2
+eval K stack = eval x stack2
where
- (x,stack1) = pop stack0
+ (x,stack1) = pop stack
(_,stack2) = pop stack1
-exec stack0 exp0@(_ :. _) = eval exp0 stack0
----------------------------------------------------------------

0 comments on commit ddcb943

Please sign in to comment.