{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-}
module Control.Carrier.Empty.Maybe
(
runEmpty
, EmptyC(..)
, module Control.Effect.Empty
) where
import Control.Algebra
import Control.Effect.Empty
import qualified Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.Trans.Maybe
runEmpty :: EmptyC m a -> m (Maybe a)
runEmpty :: EmptyC m a -> m (Maybe a)
runEmpty (EmptyC m :: MaybeT m a
m) = MaybeT m a -> m (Maybe a)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT MaybeT m a
m
{-# INLINE runEmpty #-}
newtype EmptyC m a = EmptyC (MaybeT m a)
deriving (Functor (EmptyC m)
a -> EmptyC m a
Functor (EmptyC m) =>
(forall a. a -> EmptyC m a)
-> (forall a b. EmptyC m (a -> b) -> EmptyC m a -> EmptyC m b)
-> (forall a b c.
(a -> b -> c) -> EmptyC m a -> EmptyC m b -> EmptyC m c)
-> (forall a b. EmptyC m a -> EmptyC m b -> EmptyC m b)
-> (forall a b. EmptyC m a -> EmptyC m b -> EmptyC m a)
-> Applicative (EmptyC m)
EmptyC m a -> EmptyC m b -> EmptyC m b
EmptyC m a -> EmptyC m b -> EmptyC m a
EmptyC m (a -> b) -> EmptyC m a -> EmptyC m b
(a -> b -> c) -> EmptyC m a -> EmptyC m b -> EmptyC m c
forall a. a -> EmptyC m a
forall a b. EmptyC m a -> EmptyC m b -> EmptyC m a
forall a b. EmptyC m a -> EmptyC m b -> EmptyC m b
forall a b. EmptyC m (a -> b) -> EmptyC m a -> EmptyC m b
forall a b c.
(a -> b -> c) -> EmptyC m a -> EmptyC m b -> EmptyC m c
forall (m :: * -> *). Monad m => Functor (EmptyC m)
forall (m :: * -> *) a. Monad m => a -> EmptyC m a
forall (m :: * -> *) a b.
Monad m =>
EmptyC m a -> EmptyC m b -> EmptyC m a
forall (m :: * -> *) a b.
Monad m =>
EmptyC m a -> EmptyC m b -> EmptyC m b
forall (m :: * -> *) a b.
Monad m =>
EmptyC m (a -> b) -> EmptyC m a -> EmptyC m b
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c) -> EmptyC m a -> EmptyC m b -> EmptyC 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
<* :: EmptyC m a -> EmptyC m b -> EmptyC m a
$c<* :: forall (m :: * -> *) a b.
Monad m =>
EmptyC m a -> EmptyC m b -> EmptyC m a
*> :: EmptyC m a -> EmptyC m b -> EmptyC m b
$c*> :: forall (m :: * -> *) a b.
Monad m =>
EmptyC m a -> EmptyC m b -> EmptyC m b
liftA2 :: (a -> b -> c) -> EmptyC m a -> EmptyC m b -> EmptyC m c
$cliftA2 :: forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c) -> EmptyC m a -> EmptyC m b -> EmptyC m c
<*> :: EmptyC m (a -> b) -> EmptyC m a -> EmptyC m b
$c<*> :: forall (m :: * -> *) a b.
Monad m =>
EmptyC m (a -> b) -> EmptyC m a -> EmptyC m b
pure :: a -> EmptyC m a
$cpure :: forall (m :: * -> *) a. Monad m => a -> EmptyC m a
$cp1Applicative :: forall (m :: * -> *). Monad m => Functor (EmptyC m)
Applicative, a -> EmptyC m b -> EmptyC m a
(a -> b) -> EmptyC m a -> EmptyC m b
(forall a b. (a -> b) -> EmptyC m a -> EmptyC m b)
-> (forall a b. a -> EmptyC m b -> EmptyC m a)
-> Functor (EmptyC m)
forall a b. a -> EmptyC m b -> EmptyC m a
forall a b. (a -> b) -> EmptyC m a -> EmptyC m b
forall (m :: * -> *) a b.
Functor m =>
a -> EmptyC m b -> EmptyC m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> EmptyC m a -> EmptyC m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> EmptyC m b -> EmptyC m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> EmptyC m b -> EmptyC m a
fmap :: (a -> b) -> EmptyC m a -> EmptyC m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> EmptyC m a -> EmptyC m b
Functor, Applicative (EmptyC m)
a -> EmptyC m a
Applicative (EmptyC m) =>
(forall a b. EmptyC m a -> (a -> EmptyC m b) -> EmptyC m b)
-> (forall a b. EmptyC m a -> EmptyC m b -> EmptyC m b)
-> (forall a. a -> EmptyC m a)
-> Monad (EmptyC m)
EmptyC m a -> (a -> EmptyC m b) -> EmptyC m b
EmptyC m a -> EmptyC m b -> EmptyC m b
forall a. a -> EmptyC m a
forall a b. EmptyC m a -> EmptyC m b -> EmptyC m b
forall a b. EmptyC m a -> (a -> EmptyC m b) -> EmptyC m b
forall (m :: * -> *). Monad m => Applicative (EmptyC m)
forall (m :: * -> *) a. Monad m => a -> EmptyC m a
forall (m :: * -> *) a b.
Monad m =>
EmptyC m a -> EmptyC m b -> EmptyC m b
forall (m :: * -> *) a b.
Monad m =>
EmptyC m a -> (a -> EmptyC m b) -> EmptyC 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 -> EmptyC m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> EmptyC m a
>> :: EmptyC m a -> EmptyC m b -> EmptyC m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
EmptyC m a -> EmptyC m b -> EmptyC m b
>>= :: EmptyC m a -> (a -> EmptyC m b) -> EmptyC m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
EmptyC m a -> (a -> EmptyC m b) -> EmptyC m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (EmptyC m)
Monad, Monad (EmptyC m)
Monad (EmptyC m) =>
(forall a. (a -> EmptyC m a) -> EmptyC m a) -> MonadFix (EmptyC m)
(a -> EmptyC m a) -> EmptyC m a
forall a. (a -> EmptyC m a) -> EmptyC m a
forall (m :: * -> *).
Monad m =>
(forall a. (a -> m a) -> m a) -> MonadFix m
forall (m :: * -> *). MonadFix m => Monad (EmptyC m)
forall (m :: * -> *) a.
MonadFix m =>
(a -> EmptyC m a) -> EmptyC m a
mfix :: (a -> EmptyC m a) -> EmptyC m a
$cmfix :: forall (m :: * -> *) a.
MonadFix m =>
(a -> EmptyC m a) -> EmptyC m a
$cp1MonadFix :: forall (m :: * -> *). MonadFix m => Monad (EmptyC m)
MonadFix, Monad (EmptyC m)
Monad (EmptyC m) =>
(forall a. IO a -> EmptyC m a) -> MonadIO (EmptyC m)
IO a -> EmptyC m a
forall a. IO a -> EmptyC m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (EmptyC m)
forall (m :: * -> *) a. MonadIO m => IO a -> EmptyC m a
liftIO :: IO a -> EmptyC m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> EmptyC m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (EmptyC m)
MonadIO, m a -> EmptyC m a
(forall (m :: * -> *) a. Monad m => m a -> EmptyC m a)
-> MonadTrans EmptyC
forall (m :: * -> *) a. Monad m => m a -> EmptyC m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> EmptyC m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> EmptyC m a
MonadTrans)
instance Fail.MonadFail m => Fail.MonadFail (EmptyC m) where
fail :: String -> EmptyC m a
fail = m a -> EmptyC m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> EmptyC m a) -> (String -> m a) -> String -> EmptyC m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
Fail.fail
{-# INLINE fail #-}
instance (Algebra sig m, Effect sig) => Algebra (Empty :+: sig) (EmptyC m) where
alg :: (:+:) Empty sig (EmptyC m) a -> EmptyC m a
alg (L Empty) = MaybeT m a -> EmptyC m a
forall (m :: * -> *) a. MaybeT m a -> EmptyC m a
EmptyC (m (Maybe a) -> MaybeT m a
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (Maybe a -> m (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing))
alg (R other :: sig (EmptyC m) a
other) = MaybeT m a -> EmptyC m a
forall (m :: * -> *) a. MaybeT m a -> EmptyC m a
EmptyC (m (Maybe a) -> MaybeT m a
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (sig m (Maybe a) -> m (Maybe a)
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Algebra sig m =>
sig m a -> m a
alg (Maybe ()
-> (forall x. Maybe (EmptyC m x) -> m (Maybe x))
-> sig (EmptyC m) a
-> sig m (Maybe a)
forall (sig :: (* -> *) -> * -> *) (ctx :: * -> *) (m :: * -> *)
(n :: * -> *) a.
(Effect sig, Functor ctx, Monad m) =>
ctx ()
-> (forall x. ctx (m x) -> n (ctx x)) -> sig m a -> sig n (ctx a)
thread (() -> Maybe ()
forall a. a -> Maybe a
Just ()) (m (Maybe x)
-> (EmptyC m x -> m (Maybe x)) -> Maybe (EmptyC m x) -> m (Maybe x)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe x -> m (Maybe x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe x
forall a. Maybe a
Nothing) EmptyC m x -> m (Maybe x)
forall (m :: * -> *) a. EmptyC m a -> m (Maybe a)
runEmpty) sig (EmptyC m) a
other)))
{-# INLINE alg #-}