summaryrefslogtreecommitdiff
path: root/paper/While/WhileCommon.icl
diff options
context:
space:
mode:
authorCamil Staps2016-06-03 12:29:24 +0200
committerCamil Staps2016-06-03 12:29:24 +0200
commit3bae104c3218ca0ee0f724464083d303fb745453 (patch)
tree2339b240b48d0fabd9c73ccd4032c70a02c4d84e /paper/While/WhileCommon.icl
parentFormatting (diff)
Rewrite eval for AExpr
Diffstat (limited to 'paper/While/WhileCommon.icl')
-rw-r--r--paper/While/WhileCommon.icl11
1 files changed, 4 insertions, 7 deletions
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