summaryrefslogtreecommitdiff
path: root/paper
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
parentFormatting (diff)
Rewrite eval for AExpr
Diffstat (limited to 'paper')
-rw-r--r--paper/While/Common.dcl1
-rw-r--r--paper/While/Common.icl3
-rw-r--r--paper/While/WhileCommon.icl11
-rw-r--r--paper/eval.tex2
4 files changed, 5 insertions, 12 deletions
diff --git a/paper/While/Common.dcl b/paper/While/Common.dcl
index db71353..876ffdd 100644
--- a/paper/While/Common.dcl
+++ b/paper/While/Common.dcl
@@ -32,7 +32,6 @@ instance toString Error
(<+) infixr 5 :: a b -> String | toString a & toString b
($) infixr 0 :: (a -> b) a -> b
-(on) infix 0 :: (b -> c) (a a -> b) -> (a a -> c)
(*>) infixl 4 :: (f a) (f b) -> f b | Applicative f
(<*) infixl 4 :: (f a) (f b) -> f a | Applicative f
diff --git a/paper/While/Common.icl b/paper/While/Common.icl
index 2c28933..4f6e4c4 100644
--- a/paper/While/Common.icl
+++ b/paper/While/Common.icl
@@ -28,9 +28,6 @@ where
($) infixr 0 :: (a -> b) a -> b
($) f x = f x
-(on) infix 0 :: (b -> c) (a a -> b) -> (a a -> c)
-(on) f g = \x y -> f (g x y)
-
(*>) infixl 4 :: (f a) (f b) -> f b | Applicative f
(*>) fa fb = const id <$> fa <*> fb
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
diff --git a/paper/eval.tex b/paper/eval.tex
index 14246f8..969a82d 100644
--- a/paper/eval.tex
+++ b/paper/eval.tex
@@ -11,7 +11,7 @@ occurs in the \CI{State} function, while the latter will occur in the \CI{eval}
implementation of \CI{AExpr}. Using monads, we can easily pass through errors.
An example will clarify:
-\lstinputlisting[firstline=40,lastline=55]{While/WhileCommon.icl}
+\lstinputlisting[firstline=40,lastline=52]{While/WhileCommon.icl}
Recall that the second argument to \CI{eval}, here \CI{st}, is of type
\CI{State}. That is, it is a function that yields an \CI{Either Error Int}. In