{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses #-}
module Control.Carrier.Lift
(
runM
, LiftC(..)
, module Control.Effect.Lift
) where
import Control.Algebra
import Control.Applicative (Alternative)
import Control.Effect.Lift
import Control.Monad (MonadPlus)
import qualified Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Data.Functor.Identity
runM :: LiftC m a -> m a
runM :: LiftC m a -> m a
runM (LiftC m :: m a
m) = m a
m
newtype LiftC m a = LiftC (m a)
deriving (Applicative (LiftC m)
LiftC m a
Applicative (LiftC m) =>
(forall a. LiftC m a)
-> (forall a. LiftC m a -> LiftC m a -> LiftC m a)
-> (forall a. LiftC m a -> LiftC m [a])
-> (forall a. LiftC m a -> LiftC m [a])
-> Alternative (LiftC m)
LiftC m a -> LiftC m a -> LiftC m a
LiftC m a -> LiftC m [a]
LiftC m a -> LiftC m [a]
forall a. LiftC m a
forall a. LiftC m a -> LiftC m [a]
forall a. LiftC m a -> LiftC m a -> LiftC m a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall (m :: * -> *). Alternative m => Applicative (LiftC m)
forall (m :: * -> *) a. Alternative m => LiftC m a
forall (m :: * -> *) a. Alternative m => LiftC m a -> LiftC m [a]
forall (m :: * -> *) a.
Alternative m =>
LiftC m a -> LiftC m a -> LiftC m a
many :: LiftC m a -> LiftC m [a]
$cmany :: forall (m :: * -> *) a. Alternative m => LiftC m a -> LiftC m [a]
some :: LiftC m a -> LiftC m [a]
$csome :: forall (m :: * -> *) a. Alternative m => LiftC m a -> LiftC m [a]
<|> :: LiftC m a -> LiftC m a -> LiftC m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
LiftC m a -> LiftC m a -> LiftC m a
empty :: LiftC m a
$cempty :: forall (m :: * -> *) a. Alternative m => LiftC m a
$cp1Alternative :: forall (m :: * -> *). Alternative m => Applicative (LiftC m)
Alternative, Functor (LiftC m)
a -> LiftC m a
Functor (LiftC m) =>
(forall a. a -> LiftC m a)
-> (forall a b. LiftC m (a -> b) -> LiftC m a -> LiftC m b)
-> (forall a b c.
(a -> b -> c) -> LiftC m a -> LiftC m b -> LiftC m c)
-> (forall a b. LiftC m a -> LiftC m b -> LiftC m b)
-> (forall a b. LiftC m a -> LiftC m b -> LiftC m a)
-> Applicative (LiftC m)
LiftC m a -> LiftC m b -> LiftC m b
LiftC m a -> LiftC m b -> LiftC m a
LiftC m (a -> b) -> LiftC m a -> LiftC m b
(a -> b -> c) -> LiftC m a -> LiftC m b -> LiftC m c
forall a. a -> LiftC m a
forall a b. LiftC m a -> LiftC m b -> LiftC m a
forall a b. LiftC m a -> LiftC m b -> LiftC m b
forall a b. LiftC m (a -> b) -> LiftC m a -> LiftC m b
forall a b c. (a -> b -> c) -> LiftC m a -> LiftC m b -> LiftC m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *). Applicative m => Functor (LiftC m)
forall (m :: * -> *) a. Applicative m => a -> LiftC m a
forall (m :: * -> *) a b.
Applicative m =>
LiftC m a -> LiftC m b -> LiftC m a
forall (m :: * -> *) a b.
Applicative m =>
LiftC m a -> LiftC m b -> LiftC m b
forall (m :: * -> *) a b.
Applicative m =>
LiftC m (a -> b) -> LiftC m a -> LiftC m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> LiftC m a -> LiftC m b -> LiftC m c
<* :: LiftC m a -> LiftC m b -> LiftC m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
LiftC m a -> LiftC m b -> LiftC m a
*> :: LiftC m a -> LiftC m b -> LiftC m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
LiftC m a -> LiftC m b -> LiftC m b
liftA2 :: (a -> b -> c) -> LiftC m a -> LiftC m b -> LiftC m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> LiftC m a -> LiftC m b -> LiftC m c
<*> :: LiftC m (a -> b) -> LiftC m a -> LiftC m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
LiftC m (a -> b) -> LiftC m a -> LiftC m b
pure :: a -> LiftC m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> LiftC m a
$cp1Applicative :: forall (m :: * -> *). Applicative m => Functor (LiftC m)
Applicative, a -> LiftC m b -> LiftC m a
(a -> b) -> LiftC m a -> LiftC m b
(forall a b. (a -> b) -> LiftC m a -> LiftC m b)
-> (forall a b. a -> LiftC m b -> LiftC m a) -> Functor (LiftC m)
forall a b. a -> LiftC m b -> LiftC m a
forall a b. (a -> b) -> LiftC m a -> LiftC m b
forall (m :: * -> *) a b. Functor m => a -> LiftC m b -> LiftC m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> LiftC m a -> LiftC m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> LiftC m b -> LiftC m a
$c<$ :: forall (m :: * -> *) a b. Functor m => a -> LiftC m b -> LiftC m a
fmap :: (a -> b) -> LiftC m a -> LiftC m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> LiftC m a -> LiftC m b
Functor, Applicative (LiftC m)
a -> LiftC m a
Applicative (LiftC m) =>
(forall a b. LiftC m a -> (a -> LiftC m b) -> LiftC m b)
-> (forall a b. LiftC m a -> LiftC m b -> LiftC m b)
-> (forall a. a -> LiftC m a)
-> Monad (LiftC m)
LiftC m a -> (a -> LiftC m b) -> LiftC m b
LiftC m a -> LiftC m b -> LiftC m b
forall a. a -> LiftC m a
forall a b. LiftC m a -> LiftC m b -> LiftC m b
forall a b. LiftC m a -> (a -> LiftC m b) -> LiftC m b
forall (m :: * -> *). Monad m => Applicative (LiftC m)
forall (m :: * -> *) a. Monad m => a -> LiftC m a
forall (m :: * -> *) a b.
Monad m =>
LiftC m a -> LiftC m b -> LiftC m b
forall (m :: * -> *) a b.
Monad m =>
LiftC m a -> (a -> LiftC m b) -> LiftC m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> LiftC m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> LiftC m a
>> :: LiftC m a -> LiftC m b -> LiftC m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
LiftC m a -> LiftC m b -> LiftC m b
>>= :: LiftC m a -> (a -> LiftC m b) -> LiftC m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
LiftC m a -> (a -> LiftC m b) -> LiftC m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (LiftC m)
Monad, Monad (LiftC m)
Monad (LiftC m) =>
(forall a. String -> LiftC m a) -> MonadFail (LiftC m)
String -> LiftC m a
forall a. String -> LiftC m a
forall (m :: * -> *).
Monad m =>
(forall a. String -> m a) -> MonadFail m
forall (m :: * -> *). MonadFail m => Monad (LiftC m)
forall (m :: * -> *) a. MonadFail m => String -> LiftC m a
fail :: String -> LiftC m a
$cfail :: forall (m :: * -> *) a. MonadFail m => String -> LiftC m a
$cp1MonadFail :: forall (m :: * -> *). MonadFail m => Monad (LiftC m)
Fail.MonadFail, Monad (LiftC m)
Monad (LiftC m) =>
(forall a. (a -> LiftC m a) -> LiftC m a) -> MonadFix (LiftC m)
(a -> LiftC m a) -> LiftC m a
forall a. (a -> LiftC m a) -> LiftC m a
forall (m :: * -> *).
Monad m =>
(forall a. (a -> m a) -> m a) -> MonadFix m
forall (m :: * -> *). MonadFix m => Monad (LiftC m)
forall (m :: * -> *) a. MonadFix m => (a -> LiftC m a) -> LiftC m a
mfix :: (a -> LiftC m a) -> LiftC m a
$cmfix :: forall (m :: * -> *) a. MonadFix m => (a -> LiftC m a) -> LiftC m a
$cp1MonadFix :: forall (m :: * -> *). MonadFix m => Monad (LiftC m)
MonadFix, Monad (LiftC m)
Monad (LiftC m) =>
(forall a. IO a -> LiftC m a) -> MonadIO (LiftC m)
IO a -> LiftC m a
forall a. IO a -> LiftC m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (LiftC m)
forall (m :: * -> *) a. MonadIO m => IO a -> LiftC m a
liftIO :: IO a -> LiftC m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> LiftC m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (LiftC m)
MonadIO, Monad (LiftC m)
Alternative (LiftC m)
LiftC m a
(Alternative (LiftC m), Monad (LiftC m)) =>
(forall a. LiftC m a)
-> (forall a. LiftC m a -> LiftC m a -> LiftC m a)
-> MonadPlus (LiftC m)
LiftC m a -> LiftC m a -> LiftC m a
forall a. LiftC m a
forall a. LiftC m a -> LiftC m a -> LiftC m a
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
forall (m :: * -> *). MonadPlus m => Monad (LiftC m)
forall (m :: * -> *). MonadPlus m => Alternative (LiftC m)
forall (m :: * -> *) a. MonadPlus m => LiftC m a
forall (m :: * -> *) a.
MonadPlus m =>
LiftC m a -> LiftC m a -> LiftC m a
mplus :: LiftC m a -> LiftC m a -> LiftC m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
LiftC m a -> LiftC m a -> LiftC m a
mzero :: LiftC m a
$cmzero :: forall (m :: * -> *) a. MonadPlus m => LiftC m a
$cp2MonadPlus :: forall (m :: * -> *). MonadPlus m => Monad (LiftC m)
$cp1MonadPlus :: forall (m :: * -> *). MonadPlus m => Alternative (LiftC m)
MonadPlus)
instance MonadTrans LiftC where
lift :: m a -> LiftC m a
lift = m a -> LiftC m a
forall (m :: * -> *) a. m a -> LiftC m a
LiftC
instance Monad m => Algebra (Lift m) (LiftC m) where
alg :: Lift m (LiftC m) a -> LiftC m a
alg (LiftWith with :: forall (ctx :: * -> *).
Functor ctx =>
ctx () -> (forall a. ctx (LiftC m a) -> m (ctx a)) -> m (ctx a)
with k :: a -> LiftC m a
k) = m (Identity a) -> LiftC m (Identity a)
forall (m :: * -> *) a. m a -> LiftC m a
LiftC (Identity ()
-> (forall a. Identity (LiftC m a) -> m (Identity a))
-> m (Identity a)
forall (ctx :: * -> *).
Functor ctx =>
ctx () -> (forall a. ctx (LiftC m a) -> m (ctx a)) -> m (ctx a)
with (() -> Identity ()
forall a. a -> Identity a
Identity ()) ((a -> Identity a) -> m a -> m (Identity a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Identity a
forall a. a -> Identity a
Identity (m a -> m (Identity a))
-> (Identity (LiftC m a) -> m a)
-> Identity (LiftC m a)
-> m (Identity a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LiftC m a -> m a
forall (m :: * -> *) a. LiftC m a -> m a
runM (LiftC m a -> m a)
-> (Identity (LiftC m a) -> LiftC m a)
-> Identity (LiftC m a)
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identity (LiftC m a) -> LiftC m a
forall a. Identity a -> a
runIdentity)) LiftC m (Identity a) -> (Identity a -> LiftC m a) -> LiftC m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> LiftC m a
k (a -> LiftC m a) -> (Identity a -> a) -> Identity a -> LiftC m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identity a -> a
forall a. Identity a -> a
runIdentity