Commit b6b0a9c7 authored by Camil Staps's avatar Camil Staps 🐧

Move <* and *> of Maybe to Data.Maybe

parent 05cc4ee7
Pipeline #8613 passed with stage
in 1 minute and 31 seconds
......@@ -49,7 +49,6 @@ many :: (f a) -> f [a] | Alternative f
*/
class (*>) infixl 4 f :: !(f a) (f b) -> f b | Applicative f
instance *> f
instance *> Maybe
/**
* Sequence actions and take the value of the left argument.
......@@ -60,7 +59,6 @@ instance *> Maybe
*/
class (<*) infixl 4 f :: !(f a) (f b) -> f a | Applicative f
instance <* f
instance <* Maybe
(<**>) infixl 4 :: (f a) (f (a -> b)) -> f b | Applicative f
......
......@@ -51,19 +51,8 @@ many v = many_v
instance *> f where *> fa fb = id <$ fa <*> fb
instance *> Maybe
where
*> (Just _) m = m
*> _ _ = Nothing
instance <* f where <* fa fb = liftA2 const fa fb
instance <* Maybe
where
<* Nothing _ = Nothing
<* m (Just _) = m
<* _ _ = Nothing
(<**>) infixl 4 :: (f a) (f (a -> b)) -> f b | Applicative f
(<**>) fa fab = liftA2 (flip ($)) fa fab
......
......@@ -2,7 +2,7 @@ definition module Data.Maybe
from StdOverloaded import class ==(..)
from Data.Functor import class Functor
from Control.Applicative import class Applicative, class Alternative
from Control.Applicative import class Applicative, class *>, class <*, class Alternative
from Control.Monad import class Monad, class MonadPlus
from Data.Monoid import class Semigroup, class Monoid
from Data.Foldable import class Foldable
......@@ -21,6 +21,8 @@ instance == (Maybe x) | == x
instance Functor Maybe
instance Applicative Maybe
instance *> Maybe
instance <* Maybe
instance Alternative Maybe
instance Monad Maybe
instance MonadPlus Maybe
......
......@@ -32,6 +32,17 @@ where
(<*>) Nothing _ = Nothing
(<*>) (Just f) ma = fmap f ma
instance *> Maybe
where
*> (Just _) m = m
*> _ _ = Nothing
instance <* Maybe
where
<* Nothing _ = Nothing
<* m (Just _) = m
<* _ _ = Nothing
instance Alternative Maybe
where
empty = Nothing
......
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