{-# LANGUAGE InstanceSigs #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.MonadicStreamFunction.Instances.ArrowChoice where
import Control.Arrow (ArrowChoice (..))
import Data.MonadicStreamFunction.Core ()
import Data.MonadicStreamFunction.InternalCore (MSF (MSF, unMSF))
instance Monad m => ArrowChoice (MSF m) where
left :: MSF m a b -> MSF m (Either a c) (Either b c)
left :: forall b c d. MSF m b c -> MSF m (Either b d) (Either c d)
left MSF m a b
sf = forall (m :: * -> *) a b. (a -> m (b, MSF m a b)) -> MSF m a b
MSF forall {b} {d}.
Either a b -> m (Either b b, MSF m (Either a d) (Either b d))
f
where
f :: Either a b -> m (Either b b, MSF m (Either a d) (Either b d))
f (Left a
a) = do (b
b, MSF m a b
sf') <- forall (m :: * -> *) a b. MSF m a b -> a -> m (b, MSF m a b)
unMSF MSF m a b
sf a
a
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a b. a -> Either a b
Left b
b, forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either b d) (Either c d)
left MSF m a b
sf')
f (Right b
c) = forall (m :: * -> *) a. Monad m => a -> m a
return (forall a b. b -> Either a b
Right b
c, forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either b d) (Either c d)
left MSF m a b
sf)