From: Camil Staps Date: Mon, 18 May 2015 18:44:36 +0000 (+0200) Subject: Cleanup eval X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=f94e453b984df71691e1a7ab705e136f9c6ddd99;p=fp1415.git Cleanup eval --- 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