repositories
/
fp1415.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7472aba
)
Cleanup eval
author
Camil Staps
<info@camilstaps.nl>
Mon, 18 May 2015 18:44:36 +0000
(20:44 +0200)
committer
Camil Staps
<info@camilstaps.nl>
Mon, 18 May 2015 18:44:36 +0000
(20:44 +0200)
fp2/week45/camil/RefactorX.icl
patch
|
blob
|
history
diff --git
a/fp2/week45/camil/RefactorX.icl
b/fp2/week45/camil/RefactorX.icl
index
9cbb6d7
..
a7bf909
100644
(file)
--- a/
fp2/week45/camil/RefactorX.icl
+++ b/
fp2/week45/camil/RefactorX.icl
@@
-58,19
+58,19
@@
remove_unused_lets x = x
\r
// evaluator met tabel van naam-waarde paren:
\r
eval :: Expr -> Val
\r
\r
// evaluator met tabel van naam-waarde paren:
\r
eval :: Expr -> Val
\r
-eval e =
fst (eval` e [])
\r
+eval e =
eval` e []
\r
where
\r
where
\r
- eval` :: Expr [(Name, Val)] ->
(Val, [(Name, Val)])
\r
- eval` (NR n) vs =
(Result n, [])
\r
- eval` (VAR s) vs =
(find s vs, [])
\r
+ eval` :: Expr [(Name, Val)] ->
Val
\r
+ eval` (NR n) vs =
Result n
\r
+ eval` (VAR s) vs =
find s vs
\r
where
\r
find :: Name [(Name, Val)] -> Val
\r
find _ [] = Undef
\r
find s [(t,v):vs]
\r
| s == t = v
\r
| otherwise = find s vs
\r
where
\r
find :: Name [(Name, Val)] -> Val
\r
find _ [] = Undef
\r
find s [(t,v):vs]
\r
| s == t = v
\r
| otherwise = find s vs
\r
- eval` (LET s e1 e2) vs = eval` e2 [(s,
fst (eval` e1 vs)
):vs]
\r
- eval` (OP e1 o e2) vs =
(op o (fst (eval` e1 vs)) (fst (eval` e2 vs)), []
)
\r
+ eval` (LET s e1 e2) vs = eval` e2 [(s,
eval` e1 vs
):vs]
\r
+ eval` (OP e1 o e2) vs =
op o (eval` e1 vs) (eval` e2 vs
)
\r
where
\r
op :: Operator Val Val -> Val
\r
op _ Undef _ = Undef
\r
where
\r
op :: Operator Val Val -> Val
\r
op _ Undef _ = Undef
\r