From 3bae104c3218ca0ee0f724464083d303fb745453 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 3 Jun 2016 12:29:24 +0200 Subject: Rewrite eval for AExpr --- paper/While/WhileCommon.icl | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'paper/While/WhileCommon.icl') diff --git a/paper/While/WhileCommon.icl b/paper/While/WhileCommon.icl index ce4f8fe..1fbebc3 100644 --- a/paper/While/WhileCommon.icl +++ b/paper/While/WhileCommon.icl @@ -46,13 +46,10 @@ where = eval a1 st >>= \r1 -> eval a2 st >>= app op r1 where - app :: Operator -> Int Int -> Either Error Int - app Add = pure on (+) - app Sub = pure on (-) - app Mul = pure on (*) - app Div = \i j -> if (j == 0) - (Left (Runtime "Division by 0")) - (pure (i / j)) + app :: Operator Int Int -> Either Error Int + app Div i 0 = Left (Runtime "Division by 0") + app op i j = Right $ (case op of + Add = (+); Sub = (-); Mul = (*); Div = (/)) i j instance eval BExpr Bool where -- cgit v1.2.3