{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.MonadicStreamFunction.Instances.ArrowPlus where
import Control.Applicative (Alternative (..))
import Control.Arrow (ArrowPlus (..), ArrowZero (..))
import Control.Monad (MonadPlus, mplus, mzero)
import Data.MonadicStreamFunction.Core ()
import Data.MonadicStreamFunction.InternalCore (MSF (MSF, unMSF))
instance (Monad m, MonadPlus m) => ArrowZero (MSF m) where
zeroArrow :: forall b c. MSF m b c
zeroArrow = forall (m :: * -> *) a b. (a -> m (b, MSF m a b)) -> MSF m a b
MSF forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> a
const forall (m :: * -> *) a. MonadPlus m => m a
mzero
instance (Monad m, MonadPlus m) => ArrowPlus (MSF m) where
MSF m b c
sf1 <+> :: forall b c. MSF m b c -> MSF m b c -> MSF m b c
<+> MSF m b c
sf2 = forall (m :: * -> *) a b. (a -> m (b, MSF m a b)) -> MSF m a b
MSF forall a b. (a -> b) -> a -> b
$ \b
a -> forall (m :: * -> *) a b. MSF m a b -> a -> m (b, MSF m a b)
unMSF MSF m b c
sf1 b
a forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` forall (m :: * -> *) a b. MSF m a b -> a -> m (b, MSF m a b)
unMSF MSF m b c
sf2 b
a
instance (Functor m, Monad m, MonadPlus m) => Alternative (MSF m a) where
empty :: forall a. MSF m a a
empty = forall (a :: * -> * -> *) b c. ArrowZero a => a b c
zeroArrow
<|> :: forall a. MSF m a a -> MSF m a a -> MSF m a a
(<|>) = forall (a :: * -> * -> *) b c.
ArrowPlus a =>
a b c -> a b c -> a b c
(<+>)