{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Control.Carrier.Empty.Maybe
(
runEmpty
, evalEmpty
, execEmpty
, EmptyC(..)
, module Control.Effect.Empty
) where
import Control.Algebra
import Control.Effect.Empty
import Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.Trans.Maybe
import Data.Functor (void)
import Data.Maybe (isJust)
runEmpty :: EmptyC m a -> m (Maybe a)
runEmpty :: forall (m :: * -> *) a. EmptyC m a -> m (Maybe a)
runEmpty (EmptyC MaybeT m a
m) = forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT MaybeT m a
m
{-# INLINE runEmpty #-}
evalEmpty :: Functor m => EmptyC m a -> m ()
evalEmpty :: forall (m :: * -> *) a. Functor m => EmptyC m a -> m ()
evalEmpty = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. EmptyC m a -> m (Maybe a)
runEmpty
{-# INLINE evalEmpty #-}
execEmpty :: Functor m => EmptyC m a -> m Bool
execEmpty :: forall (m :: * -> *) a. Functor m => EmptyC m a -> m Bool
execEmpty = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Maybe a -> Bool
isJust forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. EmptyC m a -> m (Maybe a)
runEmpty
{-# INLINE execEmpty #-}
newtype EmptyC m a = EmptyC (MaybeT m a)
deriving (Algebra (Empty :+: sig), 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
<* :: forall a b. 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
*> :: forall a b. 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 :: forall a b c.
(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
<*> :: forall a b. 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 :: forall a. a -> EmptyC m a
$cpure :: forall (m :: * -> *) a. Monad m => a -> EmptyC m a
Applicative, 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
<$ :: forall a b. a -> EmptyC m b -> EmptyC m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> EmptyC m b -> EmptyC m a
fmap :: forall a b. (a -> b) -> EmptyC m a -> EmptyC m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> EmptyC m a -> EmptyC m b
Functor, 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 :: forall a. a -> EmptyC m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> EmptyC m a
>> :: forall a b. 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
>>= :: forall a 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
Monad, 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 :: forall a. (a -> EmptyC m a) -> EmptyC m a
$cmfix :: forall (m :: * -> *) a.
MonadFix m =>
(a -> EmptyC m a) -> EmptyC m a
MonadFix, 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 :: forall a. IO a -> EmptyC m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> EmptyC m a
MonadIO, 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 :: forall (m :: * -> *) a. Monad m => 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 :: forall a. String -> EmptyC m a
fail = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadFail m => String -> m a
Fail.fail
{-# INLINE fail #-}