From f94e453b984df71691e1a7ab705e136f9c6ddd99 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 18 May 2015 20:44:36 +0200 Subject: [PATCH] Cleanup eval --- fp2/week45/camil/RefactorX.icl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fp2/week45/camil/RefactorX.icl b/fp2/week45/camil/RefactorX.icl index 9cbb6d7..a7bf909 100644 --- a/fp2/week45/camil/RefactorX.icl +++ b/fp2/week45/camil/RefactorX.icl @@ -58,19 +58,19 @@ remove_unused_lets x = x // evaluator met tabel van naam-waarde paren: eval :: Expr -> Val -eval e = fst (eval` e []) +eval e = eval` e [] where - eval` :: Expr [(Name, Val)] -> (Val, [(Name, Val)]) - eval` (NR n) vs = (Result n, []) - eval` (VAR s) vs = (find s vs, []) + eval` :: Expr [(Name, Val)] -> Val + eval` (NR n) vs = Result n + eval` (VAR s) vs = find s vs where find :: Name [(Name, Val)] -> Val find _ [] = Undef find s [(t,v):vs] | s == t = v | otherwise = find s vs - eval` (LET s e1 e2) vs = eval` e2 [(s,fst (eval` e1 vs)):vs] - eval` (OP e1 o e2) vs = (op o (fst (eval` e1 vs)) (fst (eval` e2 vs)), []) + eval` (LET s e1 e2) vs = eval` e2 [(s,eval` e1 vs):vs] + eval` (OP e1 o e2) vs = op o (eval` e1 vs) (eval` e2 vs) where op :: Operator Val Val -> Val op _ Undef _ = Undef -- 2.20.1