Commit de1a8939 authored by Steffen Michels's avatar Steffen Michels

Merge branch 'fix-sequence-operators' into 'master'

Fix evaluation order for <* of Maybe and Either

See merge request !56
parents fcf24ace 5c1660bd
......@@ -49,6 +49,8 @@ many :: (f a) -> f [a] | Alternative f
* types there are more efficient possibilities. Making this a class with a
* default implementation allows overriding the instance in such cases, like
* for Maybe here.
* Be aware that the execution order has to be correct: the left hand side must
* be evaluated before the right hand side.
*/
class (*>) infixl 4 f :: (f a) (f b) -> f b | Applicative f
instance *> f
......@@ -58,6 +60,8 @@ instance *> Maybe
* Sequence actions and take the value of the left argument.
* For the reason behind making this a class rather than a normal function, see
* the documentation on *>.
* Be aware that the execution order has to be correct: the left hand side must
* be evaluated before the right hand side.
*/
class (<*) infixl 4 f :: (f a) (f b) -> f a | Applicative f
instance <* f
......
......@@ -82,6 +82,7 @@ instance <* f where <* fa fb = liftA2 const fa fb
instance <* Maybe
where
<* Nothing _ = Nothing
<* m (Just _) = m
<* _ _ = Nothing
......
......@@ -20,8 +20,9 @@ where
instance <* (Either e)
where
<* l (Right y) = l
<* e _ = e
<* (Left l) _ = Left l
<* _ (Left l) = Left l
<* x _ = x
instance Monad (Either e) where
bind (Left l) _ = Left l
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment