fused-effects-1.0.2.0: A fast, flexible, fused effect system.
Safe HaskellNone
LanguageHaskell2010

Control.Effect.NonDet

Description

An effect modelling nondeterminism with choice and failure.

Nondeterministic operations are encapsulated by the Alternative class, where empty represents failure and <|> represents choice. This module re-exports the Alternative interface. If you can't or don't want to use Alternative, you can use the empty and <|> operations (from Control.Effect.Empty and Control.Effect.Choose respectively) directly, as the NonDet effect is the composition of Choose and Empty.

Predefined carriers:

  • Control.Carrier.NonDet.Church, which collects all branches' results using an Alternative functor.
  • If NonDet is the last effect in a stack, it can be interpreted directly into a [].

Since: 0.1.0.0

Synopsis

NonDet effects

type NonDet = Empty :+: Choose Source #

The nondeterminism effect is the composition of Empty and Choose effects.

Since: 0.1.0.0

newtype Choose m k Source #

Since: 1.0.0.0

Constructors

Choose (Bool -> m k) 

Instances

Instances details
Effect Choose Source # 
Instance details

Defined in Control.Effect.Choose.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Choose m a -> Choose n (ctx a) Source #

HFunctor Choose Source # 
Instance details

Defined in Control.Effect.Choose.Internal

Methods

hmap :: Functor m => (forall x. m x -> n x) -> Choose m a -> Choose n a Source #

Algebra Choose NonEmpty Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Choose NonEmpty a -> NonEmpty a Source #

Algebra NonDet [] Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: NonDet [] a -> [a] Source #

Functor m => Functor (Choose m) Source # 
Instance details

Defined in Control.Effect.Choose.Internal

Methods

fmap :: (a -> b) -> Choose m a -> Choose m b #

(<$) :: a -> Choose m b -> Choose m a #

Generic1 (Choose m :: Type -> Type) Source # 
Instance details

Defined in Control.Effect.Choose.Internal

Associated Types

type Rep1 (Choose m) :: k -> Type #

Methods

from1 :: forall (a :: k). Choose m a -> Rep1 (Choose m) a #

to1 :: forall (a :: k). Rep1 (Choose m) a -> Choose m a #

(Algebra sig m, Effect sig) => Algebra (Choose :+: sig) (ChooseC m) Source # 
Instance details

Defined in Control.Carrier.Choose.Church

Methods

alg :: (Choose :+: sig) (ChooseC m) a -> ChooseC m a Source #

(Algebra sig m, Effect sig) => Algebra (NonDet :+: sig) (NonDetC m) Source # 
Instance details

Defined in Control.Carrier.NonDet.Church

Methods

alg :: (NonDet :+: sig) (NonDetC m) a -> NonDetC m a Source #

(Algebra sig m, Effect sig) => Algebra (Cut :+: (NonDet :+: sig)) (CutC m) Source # 
Instance details

Defined in Control.Carrier.Cut.Church

Methods

alg :: (Cut :+: (NonDet :+: sig)) (CutC m) a -> CutC m a Source #

(Algebra sig m, Effect sig) => Algebra (Cull :+: (NonDet :+: sig)) (CullC m) Source # 
Instance details

Defined in Control.Carrier.Cull.Church

Methods

alg :: (Cull :+: (NonDet :+: sig)) (CullC m) a -> CullC m a Source #

type Rep1 (Choose m :: Type -> Type) Source # 
Instance details

Defined in Control.Effect.Choose.Internal

type Rep1 (Choose m :: Type -> Type) = D1 ('MetaData "Choose" "Control.Effect.Choose.Internal" "fused-effects-1.0.2.0-inplace" 'True) (C1 ('MetaCons "Choose" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (((->) Bool :: Type -> Type) :.: Rec1 m)))

data Empty (m :: * -> *) k Source #

Since: 1.0.0.0

Constructors

Empty 

Instances

Instances details
Effect Empty Source # 
Instance details

Defined in Control.Effect.Empty.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Empty m a -> Empty n (ctx a) Source #

HFunctor Empty Source # 
Instance details

Defined in Control.Effect.Empty.Internal

Methods

hmap :: Functor m => (forall x. m x -> n x) -> Empty m a -> Empty n a Source #

Algebra Empty Maybe Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Empty Maybe a -> Maybe a Source #

Algebra NonDet [] Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: NonDet [] a -> [a] Source #

Functor (Empty m) Source # 
Instance details

Defined in Control.Effect.Empty.Internal

Methods

fmap :: (a -> b) -> Empty m a -> Empty m b #

(<$) :: a -> Empty m b -> Empty m a #

Generic1 (Empty m :: Type -> Type) Source # 
Instance details

Defined in Control.Effect.Empty.Internal

Associated Types

type Rep1 (Empty m) :: k -> Type #

Methods

from1 :: forall (a :: k). Empty m a -> Rep1 (Empty m) a #

to1 :: forall (a :: k). Rep1 (Empty m) a -> Empty m a #

(Algebra sig m, Effect sig) => Algebra (Empty :+: sig) (EmptyC m) Source # 
Instance details

Defined in Control.Carrier.Empty.Maybe

Methods

alg :: (Empty :+: sig) (EmptyC m) a -> EmptyC m a Source #

(Algebra sig m, Effect sig) => Algebra (NonDet :+: sig) (NonDetC m) Source # 
Instance details

Defined in Control.Carrier.NonDet.Church

Methods

alg :: (NonDet :+: sig) (NonDetC m) a -> NonDetC m a Source #

(Algebra sig m, Effect sig) => Algebra (Cut :+: (NonDet :+: sig)) (CutC m) Source # 
Instance details

Defined in Control.Carrier.Cut.Church

Methods

alg :: (Cut :+: (NonDet :+: sig)) (CutC m) a -> CutC m a Source #

(Algebra sig m, Effect sig) => Algebra (Cull :+: (NonDet :+: sig)) (CullC m) Source # 
Instance details

Defined in Control.Carrier.Cull.Church

Methods

alg :: (Cull :+: (NonDet :+: sig)) (CullC m) a -> CullC m a Source #

type Rep1 (Empty m :: Type -> Type) Source # 
Instance details

Defined in Control.Effect.Empty.Internal

type Rep1 (Empty m :: Type -> Type) = D1 ('MetaData "Empty" "Control.Effect.Empty.Internal" "fused-effects-1.0.2.0-inplace" 'False) (C1 ('MetaCons "Empty" 'PrefixI 'False) (U1 :: Type -> Type))

oneOf :: (Foldable t, Alternative m) => t a -> m a Source #

Nondeterministically choose an element from a Foldable collection. This can be used to emulate the style of nondeterminism associated with programming in the list monad:

  pythagoreanTriples = do
    a <- oneOf [1..10]
    b <- oneOf [1..10]
    c <- oneOf [1..10]
    guard (a^2 + b^2 == c^2)
    pure (a, b, c)

Since: 1.0.0.0

foldMapA :: (Foldable t, Alternative m) => (a -> m b) -> t a -> m b Source #

Map a Foldable collection of values into a nondeterministic computation using the supplied action.

Since: 1.0.0.0

Re-exports

class Applicative f => Alternative (f :: Type -> Type) where #

A monoid on applicative functors.

If defined, some and many should be the least solutions of the equations:

Minimal complete definition

empty, (<|>)

Methods

empty :: f a #

The identity of <|>

(<|>) :: f a -> f a -> f a infixl 3 #

An associative binary operation

some :: f a -> f [a] #

One or more.

many :: f a -> f [a] #

Zero or more.

Instances

Instances details
Alternative []

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

empty :: [a] #

(<|>) :: [a] -> [a] -> [a] #

some :: [a] -> [[a]] #

many :: [a] -> [[a]] #

Alternative Maybe

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

empty :: Maybe a #

(<|>) :: Maybe a -> Maybe a -> Maybe a #

some :: Maybe a -> Maybe [a] #

many :: Maybe a -> Maybe [a] #

Alternative IO

Since: base-4.9.0.0

Instance details

Defined in GHC.Base

Methods

empty :: IO a #

(<|>) :: IO a -> IO a -> IO a #

some :: IO a -> IO [a] #

many :: IO a -> IO [a] #

Alternative Option

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Methods

empty :: Option a #

(<|>) :: Option a -> Option a -> Option a #

some :: Option a -> Option [a] #

many :: Option a -> Option [a] #

Alternative ZipList

Since: base-4.11.0.0

Instance details

Defined in Control.Applicative

Methods

empty :: ZipList a #

(<|>) :: ZipList a -> ZipList a -> ZipList a #

some :: ZipList a -> ZipList [a] #

many :: ZipList a -> ZipList [a] #

Alternative ReadP

Since: base-4.6.0.0

Instance details

Defined in Text.ParserCombinators.ReadP

Methods

empty :: ReadP a #

(<|>) :: ReadP a -> ReadP a -> ReadP a #

some :: ReadP a -> ReadP [a] #

many :: ReadP a -> ReadP [a] #

Alternative P

Since: base-4.5.0.0

Instance details

Defined in Text.ParserCombinators.ReadP

Methods

empty :: P a #

(<|>) :: P a -> P a -> P a #

some :: P a -> P [a] #

many :: P a -> P [a] #

Alternative (U1 :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

empty :: U1 a #

(<|>) :: U1 a -> U1 a -> U1 a #

some :: U1 a -> U1 [a] #

many :: U1 a -> U1 [a] #

MonadPlus m => Alternative (WrappedMonad m)

Since: base-2.1

Instance details

Defined in Control.Applicative

Methods

empty :: WrappedMonad m a #

(<|>) :: WrappedMonad m a -> WrappedMonad m a -> WrappedMonad m a #

some :: WrappedMonad m a -> WrappedMonad m [a] #

many :: WrappedMonad m a -> WrappedMonad m [a] #

ArrowPlus a => Alternative (ArrowMonad a)

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

empty :: ArrowMonad a a0 #

(<|>) :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 #

some :: ArrowMonad a a0 -> ArrowMonad a [a0] #

many :: ArrowMonad a a0 -> ArrowMonad a [a0] #

Alternative (Proxy :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in Data.Proxy

Methods

empty :: Proxy a #

(<|>) :: Proxy a -> Proxy a -> Proxy a #

some :: Proxy a -> Proxy [a] #

many :: Proxy a -> Proxy [a] #

(Functor m, Monad m) => Alternative (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

empty :: MaybeT m a #

(<|>) :: MaybeT m a -> MaybeT m a -> MaybeT m a #

some :: MaybeT m a -> MaybeT m [a] #

many :: MaybeT m a -> MaybeT m [a] #

Alternative m => Alternative (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Printing

Methods

empty :: TraceC m a #

(<|>) :: TraceC m a -> TraceC m a -> TraceC m a #

some :: TraceC m a -> TraceC m [a] #

many :: TraceC m a -> TraceC m [a] #

Alternative m => Alternative (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Ignoring

Methods

empty :: TraceC m a #

(<|>) :: TraceC m a -> TraceC m a -> TraceC m a #

some :: TraceC m a -> TraceC m [a] #

many :: TraceC m a -> TraceC m [a] #

(Alternative m, Monad m) => Alternative (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Returning

Methods

empty :: TraceC m a #

(<|>) :: TraceC m a -> TraceC m a -> TraceC m a #

some :: TraceC m a -> TraceC m [a] #

many :: TraceC m a -> TraceC m [a] #

Alternative (NonDetC m) Source # 
Instance details

Defined in Control.Carrier.NonDet.Church

Methods

empty :: NonDetC m a #

(<|>) :: NonDetC m a -> NonDetC m a -> NonDetC m a #

some :: NonDetC m a -> NonDetC m [a] #

many :: NonDetC m a -> NonDetC m [a] #

Alternative m => Alternative (LiftC m) Source # 
Instance details

Defined in Control.Carrier.Lift

Methods

empty :: LiftC m a #

(<|>) :: LiftC m a -> LiftC m a -> LiftC m a #

some :: LiftC m a -> LiftC m [a] #

many :: LiftC m a -> LiftC m [a] #

(Alternative m, Monad m) => Alternative (FreshC m) Source # 
Instance details

Defined in Control.Carrier.Fresh.Strict

Methods

empty :: FreshC m a #

(<|>) :: FreshC m a -> FreshC m a -> FreshC m a #

some :: FreshC m a -> FreshC m [a] #

many :: FreshC m a -> FreshC m [a] #

(Alternative m, Monad m) => Alternative (FailC m) Source # 
Instance details

Defined in Control.Carrier.Fail.Either

Methods

empty :: FailC m a #

(<|>) :: FailC m a -> FailC m a -> FailC m a #

some :: FailC m a -> FailC m [a] #

many :: FailC m a -> FailC m [a] #

Alternative (CutC m) Source # 
Instance details

Defined in Control.Carrier.Cut.Church

Methods

empty :: CutC m a #

(<|>) :: CutC m a -> CutC m a -> CutC m a #

some :: CutC m a -> CutC m [a] #

many :: CutC m a -> CutC m [a] #

Alternative (CullC m) Source # 
Instance details

Defined in Control.Carrier.Cull.Church

Methods

empty :: CullC m a #

(<|>) :: CullC m a -> CullC m a -> CullC m a #

some :: CullC m a -> CullC m [a] #

many :: CullC m a -> CullC m [a] #

Alternative f => Alternative (Rec1 f)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

empty :: Rec1 f a #

(<|>) :: Rec1 f a -> Rec1 f a -> Rec1 f a #

some :: Rec1 f a -> Rec1 f [a] #

many :: Rec1 f a -> Rec1 f [a] #

(ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b)

Since: base-2.1

Instance details

Defined in Control.Applicative

Methods

empty :: WrappedArrow a b a0 #

(<|>) :: WrappedArrow a b a0 -> WrappedArrow a b a0 -> WrappedArrow a b a0 #

some :: WrappedArrow a b a0 -> WrappedArrow a b [a0] #

many :: WrappedArrow a b a0 -> WrappedArrow a b [a0] #

Alternative f => Alternative (Ap f)

Since: base-4.12.0.0

Instance details

Defined in Data.Monoid

Methods

empty :: Ap f a #

(<|>) :: Ap f a -> Ap f a -> Ap f a #

some :: Ap f a -> Ap f [a] #

many :: Ap f a -> Ap f [a] #

Alternative f => Alternative (Alt f)

Since: base-4.8.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

empty :: Alt f a #

(<|>) :: Alt f a -> Alt f a -> Alt f a #

some :: Alt f a -> Alt f [a] #

many :: Alt f a -> Alt f [a] #

(Monoid w, Alternative m) => Alternative (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.Strict

Methods

empty :: WriterT w m a #

(<|>) :: WriterT w m a -> WriterT w m a -> WriterT w m a #

some :: WriterT w m a -> WriterT w m [a] #

many :: WriterT w m a -> WriterT w m [a] #

(Monoid w, Alternative m) => Alternative (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

Methods

empty :: WriterT w m a #

(<|>) :: WriterT w m a -> WriterT w m a -> WriterT w m a #

some :: WriterT w m a -> WriterT w m [a] #

many :: WriterT w m a -> WriterT w m [a] #

(Functor m, MonadPlus m) => Alternative (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Strict

Methods

empty :: StateT s m a #

(<|>) :: StateT s m a -> StateT s m a -> StateT s m a #

some :: StateT s m a -> StateT s m [a] #

many :: StateT s m a -> StateT s m [a] #

(Functor m, MonadPlus m) => Alternative (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

empty :: StateT s m a #

(<|>) :: StateT s m a -> StateT s m a -> StateT s m a #

some :: StateT s m a -> StateT s m [a] #

many :: StateT s m a -> StateT s m [a] #

Alternative m => Alternative (ReaderT r m) 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

empty :: ReaderT r m a #

(<|>) :: ReaderT r m a -> ReaderT r m a -> ReaderT r m a #

some :: ReaderT r m a -> ReaderT r m [a] #

many :: ReaderT r m a -> ReaderT r m [a] #

Alternative m => Alternative (IdentityT m) 
Instance details

Defined in Control.Monad.Trans.Identity

Methods

empty :: IdentityT m a #

(<|>) :: IdentityT m a -> IdentityT m a -> IdentityT m a #

some :: IdentityT m a -> IdentityT m [a] #

many :: IdentityT m a -> IdentityT m [a] #

(Functor m, Monad m, Monoid e) => Alternative (ExceptT e m) 
Instance details

Defined in Control.Monad.Trans.Except

Methods

empty :: ExceptT e m a #

(<|>) :: ExceptT e m a -> ExceptT e m a -> ExceptT e m a #

some :: ExceptT e m a -> ExceptT e m [a] #

many :: ExceptT e m a -> ExceptT e m [a] #

(Alternative m, Monad m) => Alternative (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.Strict

Methods

empty :: StateC s m a #

(<|>) :: StateC s m a -> StateC s m a -> StateC s m a #

some :: StateC s m a -> StateC s m [a] #

many :: StateC s m a -> StateC s m [a] #

(Alternative m, Monad m) => Alternative (WriterC w m) Source # 
Instance details

Defined in Control.Carrier.Writer.Strict

Methods

empty :: WriterC w m a #

(<|>) :: WriterC w m a -> WriterC w m a -> WriterC w m a #

some :: WriterC w m a -> WriterC w m [a] #

many :: WriterC w m a -> WriterC w m [a] #

(Alternative m, Monad m) => Alternative (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.Lazy

Methods

empty :: StateC s m a #

(<|>) :: StateC s m a -> StateC s m a -> StateC s m a #

some :: StateC s m a -> StateC s m [a] #

many :: StateC s m a -> StateC s m [a] #

Alternative m => Alternative (ReaderC r m) Source # 
Instance details

Defined in Control.Carrier.Reader

Methods

empty :: ReaderC r m a #

(<|>) :: ReaderC r m a -> ReaderC r m a -> ReaderC r m a #

some :: ReaderC r m a -> ReaderC r m [a] #

many :: ReaderC r m a -> ReaderC r m [a] #

(Alternative m, Monad m) => Alternative (ErrorC e m) Source #

ErrorC passes Alternative operations along to the underlying monad m, rather than combining errors à la ExceptT.

Instance details

Defined in Control.Carrier.Error.Either

Methods

empty :: ErrorC e m a #

(<|>) :: ErrorC e m a -> ErrorC e m a -> ErrorC e m a #

some :: ErrorC e m a -> ErrorC e m [a] #

many :: ErrorC e m a -> ErrorC e m [a] #

(Alternative m, Monad m) => Alternative (ThrowC e m) Source # 
Instance details

Defined in Control.Carrier.Throw.Either

Methods

empty :: ThrowC e m a #

(<|>) :: ThrowC e m a -> ThrowC e m a -> ThrowC e m a #

some :: ThrowC e m a -> ThrowC e m [a] #

many :: ThrowC e m a -> ThrowC e m [a] #

(Alternative f, Alternative g) => Alternative (f :*: g)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

empty :: (f :*: g) a #

(<|>) :: (f :*: g) a -> (f :*: g) a -> (f :*: g) a #

some :: (f :*: g) a -> (f :*: g) [a] #

many :: (f :*: g) a -> (f :*: g) [a] #

(Alternative f, Alternative g) => Alternative (Product f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Product

Methods

empty :: Product f g a #

(<|>) :: Product f g a -> Product f g a -> Product f g a #

some :: Product f g a -> Product f g [a] #

many :: Product f g a -> Product f g [a] #

Alternative m => Alternative (InterpretC s sig m) Source # 
Instance details

Defined in Control.Carrier.Interpret

Methods

empty :: InterpretC s sig m a #

(<|>) :: InterpretC s sig m a -> InterpretC s sig m a -> InterpretC s sig m a #

some :: InterpretC s sig m a -> InterpretC s sig m [a] #

many :: InterpretC s sig m a -> InterpretC s sig m [a] #

Alternative f => Alternative (M1 i c f)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

empty :: M1 i c f a #

(<|>) :: M1 i c f a -> M1 i c f a -> M1 i c f a #

some :: M1 i c f a -> M1 i c f [a] #

many :: M1 i c f a -> M1 i c f [a] #

(Alternative f, Applicative g) => Alternative (f :.: g)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

empty :: (f :.: g) a #

(<|>) :: (f :.: g) a -> (f :.: g) a -> (f :.: g) a #

some :: (f :.: g) a -> (f :.: g) [a] #

many :: (f :.: g) a -> (f :.: g) [a] #

(Alternative f, Applicative g) => Alternative (Compose f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

Methods

empty :: Compose f g a #

(<|>) :: Compose f g a -> Compose f g a -> Compose f g a #

some :: Compose f g a -> Compose f g [a] #

many :: Compose f g a -> Compose f g [a] #

(Monoid w, Functor m, MonadPlus m) => Alternative (RWST r w s m) 
Instance details

Defined in Control.Monad.Trans.RWS.Strict

Methods

empty :: RWST r w s m a #

(<|>) :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

some :: RWST r w s m a -> RWST r w s m [a] #

many :: RWST r w s m a -> RWST r w s m [a] #

(Monoid w, Functor m, MonadPlus m) => Alternative (RWST r w s m) 
Instance details

Defined in Control.Monad.Trans.RWS.Lazy

Methods

empty :: RWST r w s m a #

(<|>) :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

some :: RWST r w s m a -> RWST r w s m [a] #

many :: RWST r w s m a -> RWST r w s m [a] #

Alternative m => Alternative (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

empty :: UnderLabel label sub m a #

(<|>) :: UnderLabel label sub m a -> UnderLabel label sub m a -> UnderLabel label sub m a #

some :: UnderLabel label sub m a -> UnderLabel label sub m [a] #

many :: UnderLabel label sub m a -> UnderLabel label sub m [a] #

Alternative (sub m) => Alternative (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

empty :: Labelled label sub m a #

(<|>) :: Labelled label sub m a -> Labelled label sub m a -> Labelled label sub m a #

some :: Labelled label sub m a -> Labelled label sub m [a] #

many :: Labelled label sub m a -> Labelled label sub m [a] #

class (HFunctor sig, Monad m) => Algebra sig m | m -> sig Source #

The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the alg method.

Since: 1.0.0.0

Minimal complete definition

alg

Instances

Instances details
Algebra Choose NonEmpty Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Choose NonEmpty a -> NonEmpty a Source #

Algebra Empty Maybe Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Empty Maybe a -> Maybe a Source #

Algebra NonDet [] Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: NonDet [] a -> [a] Source #

Algebra sig m => Algebra sig (Alt m) Source #

This instance permits effectful actions to be lifted into the Alt monad, which eases the invocation of repeated alternation with <|>:

a <|> b <|> c <|> d

is equivalent to

getAlt (mconcat [a, b, c, d])

Since: 1.0.1.0

Instance details

Defined in Control.Algebra

Methods

alg :: sig (Alt m) a -> Alt m a Source #

Algebra sig m => Algebra sig (Ap m) Source #

This instance permits effectful actions to be lifted into the Ap monad given a monoidal return type, which can provide clarity when chaining calls to mappend.

mappend <$> act1 <*> (mappend <$> act2 <*> act3)

is equivalent to

getAp (act1 <> act2 <> act3)

Since: 1.0.1.0

Instance details

Defined in Control.Algebra

Methods

alg :: sig (Ap m) a -> Ap m a Source #

Algebra sig m => Algebra sig (IdentityT m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: sig (IdentityT m) a -> IdentityT m a Source #

Algebra (Lift IO) IO Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Lift IO IO a -> IO a Source #

Algebra (Lift Identity) Identity Source # 
Instance details

Defined in Control.Algebra

Monad m => Algebra (Lift m) (LiftC m) Source # 
Instance details

Defined in Control.Carrier.Lift

Methods

alg :: Lift m (LiftC m) a -> LiftC m a Source #

Algebra (Error e) (Either e) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Error e (Either e) a -> Either e a Source #

Monoid w => Algebra (Writer w) ((,) w) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Writer w ((,) w) a -> (w, a) Source #

Algebra (Reader r) ((->) r :: Type -> Type) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: Reader r ((->) r) a -> r -> a Source #

(Algebra sig m, Effect sig) => Algebra (Choose :+: sig) (ChooseC m) Source # 
Instance details

Defined in Control.Carrier.Choose.Church

Methods

alg :: (Choose :+: sig) (ChooseC m) a -> ChooseC m a Source #

(Algebra sig m, Effect sig) => Algebra (Empty :+: sig) (EmptyC m) Source # 
Instance details

Defined in Control.Carrier.Empty.Maybe

Methods

alg :: (Empty :+: sig) (EmptyC m) a -> EmptyC m a Source #

(Algebra sig m, Effect sig) => Algebra (NonDet :+: sig) (NonDetC m) Source # 
Instance details

Defined in Control.Carrier.NonDet.Church

Methods

alg :: (NonDet :+: sig) (NonDetC m) a -> NonDetC m a Source #

(MonadIO m, Algebra sig m) => Algebra (Trace :+: sig) (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Printing

Methods

alg :: (Trace :+: sig) (TraceC m) a -> TraceC m a Source #

Algebra sig m => Algebra (Trace :+: sig) (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Ignoring

Methods

alg :: (Trace :+: sig) (TraceC m) a -> TraceC m a Source #

(Algebra sig m, Effect sig) => Algebra (Trace :+: sig) (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Returning

Methods

alg :: (Trace :+: sig) (TraceC m) a -> TraceC m a Source #

(Algebra sig m, Effect sig) => Algebra (Fail :+: sig) (FailC m) Source # 
Instance details

Defined in Control.Carrier.Fail.Either

Methods

alg :: (Fail :+: sig) (FailC m) a -> FailC m a Source #

(Algebra sig m, Effect sig) => Algebra (Fresh :+: sig) (FreshC m) Source # 
Instance details

Defined in Control.Carrier.Fresh.Strict

Methods

alg :: (Fresh :+: sig) (FreshC m) a -> FreshC m a Source #

(Algebra sig m, Effect sig) => Algebra (Cut :+: (NonDet :+: sig)) (CutC m) Source # 
Instance details

Defined in Control.Carrier.Cut.Church

Methods

alg :: (Cut :+: (NonDet :+: sig)) (CutC m) a -> CutC m a Source #

(Algebra sig m, Effect sig) => Algebra (Cull :+: (NonDet :+: sig)) (CullC m) Source # 
Instance details

Defined in Control.Carrier.Cull.Church

Methods

alg :: (Cull :+: (NonDet :+: sig)) (CullC m) a -> CullC m a Source #

Algebra sig m => Algebra (Reader r :+: sig) (ReaderT r m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Reader r :+: sig) (ReaderT r m) a -> ReaderT r m a Source #

Algebra sig m => Algebra (Reader r :+: sig) (ReaderC r m) Source # 
Instance details

Defined in Control.Carrier.Reader

Methods

alg :: (Reader r :+: sig) (ReaderC r m) a -> ReaderC r m a Source #

(Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateT s m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (State s :+: sig) (StateT s m) a -> StateT s m a Source #

(Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateT s m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (State s :+: sig) (StateT s m) a -> StateT s m a Source #

(Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.Strict

Methods

alg :: (State s :+: sig) (StateC s m) a -> StateC s m a Source #

(Algebra sig m, Effect sig) => Algebra (State s :+: sig) (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.Lazy

Methods

alg :: (State s :+: sig) (StateC s m) a -> StateC s m a Source #

(Algebra sig m, Effect sig) => Algebra (Throw e :+: sig) (ThrowC e m) Source # 
Instance details

Defined in Control.Carrier.Throw.Either

Methods

alg :: (Throw e :+: sig) (ThrowC e m) a -> ThrowC e m a Source #

(Algebra sig m, Effect sig) => Algebra (Error e :+: sig) (ExceptT e m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Error e :+: sig) (ExceptT e m) a -> ExceptT e m a Source #

(Algebra sig m, Effect sig) => Algebra (Error e :+: sig) (ErrorC e m) Source # 
Instance details

Defined in Control.Carrier.Error.Either

Methods

alg :: (Error e :+: sig) (ErrorC e m) a -> ErrorC e m a Source #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Writer w :+: sig) (WriterT w m) a -> WriterT w m a Source #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Writer w :+: sig) (WriterT w m) a -> WriterT w m a Source #

(Monoid w, Algebra sig m, Effect sig) => Algebra (Writer w :+: sig) (WriterC w m) Source # 
Instance details

Defined in Control.Carrier.Writer.Strict

Methods

alg :: (Writer w :+: sig) (WriterC w m) a -> WriterC w m a Source #

(HFunctor eff, HFunctor sig, Reifies s (Handler eff m), Monad m, Algebra sig m) => Algebra (eff :+: sig) (InterpretC s eff m) Source # 
Instance details

Defined in Control.Carrier.Interpret

Methods

alg :: (eff :+: sig) (InterpretC s eff m) a -> InterpretC s eff m a Source #

(LabelledMember label sub sig, HFunctor sub, Algebra sig m) => Algebra (sub :+: sig) (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

alg :: (sub :+: sig) (UnderLabel label sub m) a -> UnderLabel label sub m a Source #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) a -> RWST r w s m a Source #

(Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # 
Instance details

Defined in Control.Algebra

Methods

alg :: (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) a -> RWST r w s m a Source #

(Algebra (eff :+: sig) (sub m), HFunctor eff, HFunctor sig) => Algebra (Labelled label eff :+: sig) (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

alg :: (Labelled label eff :+: sig) (Labelled label sub m) a -> Labelled label sub m a Source #

class HFunctor sig => Effect sig Source #

The class of effect types, which must:

  1. Be functorial in their last two arguments, and
  2. Support threading effects in higher-order positions through using the carrier’s suspended context.

All first-order effects (those without existential occurrences of m) admit a default definition of thread provided a Generic1 instance is available for the effect.

Since: 1.0.0.0

Instances

Instances details
Effect Choose Source # 
Instance details

Defined in Control.Effect.Choose.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Choose m a -> Choose n (ctx a) Source #

Effect Empty Source # 
Instance details

Defined in Control.Effect.Empty.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Empty m a -> Empty n (ctx a) Source #

Effect Trace Source # 
Instance details

Defined in Control.Effect.Trace

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Trace m a -> Trace n (ctx a) Source #

Effect Fresh Source # 
Instance details

Defined in Control.Effect.Fresh

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Fresh m a -> Fresh n (ctx a) Source #

Effect Cut Source # 
Instance details

Defined in Control.Effect.Cut

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Cut m a -> Cut n (ctx a) Source #

Effect Cull Source # 
Instance details

Defined in Control.Effect.Cull

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Cull m a -> Cull n (ctx a) Source #

Effect (Catch e) Source # 
Instance details

Defined in Control.Effect.Catch.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Catch e m a -> Catch e n (ctx a) Source #

Functor sig => Effect (Lift sig) Source # 
Instance details

Defined in Control.Effect.Lift.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Lift sig m a -> Lift sig n (ctx a) Source #

Effect (Reader r) Source # 
Instance details

Defined in Control.Effect.Reader.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Reader r m a -> Reader r n (ctx a) Source #

Effect (State s) Source # 
Instance details

Defined in Control.Effect.State.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> State s m a -> State s n (ctx a) Source #

Effect (Throw e) Source # 
Instance details

Defined in Control.Effect.Throw.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Throw e m a -> Throw e n (ctx a) Source #

Effect (Writer w) Source # 
Instance details

Defined in Control.Effect.Writer.Internal

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Writer w m a -> Writer w n (ctx a) Source #

(Effect f, Effect g) => Effect (f :+: g) Source # 
Instance details

Defined in Control.Effect.Sum

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> (f :+: g) m a -> (f :+: g) n (ctx a) Source #

Effect sub => Effect (Labelled label sub) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

thread :: (Functor ctx, Monad m) => ctx () -> (forall x. ctx (m x) -> n (ctx x)) -> Labelled label sub m a -> Labelled label sub n (ctx a) Source #

type Has eff sig m = (Members eff sig, Algebra sig m) Source #

m is a carrier for sig containing eff.

Note that if eff is a sum, it will be decomposed into multiple Member constraints. While this technically allows one to combine multiple unrelated effects into a single Has constraint, doing so has two significant drawbacks:

  1. Due to a problem with recursive type families, this can lead to significantly slower compiles.
  2. It defeats ghc’s warnings for redundant constraints, and thus can lead to a proliferation of redundant constraints as code is changed.

class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #

Monads that also support choice and failure.

Minimal complete definition

Nothing

Methods

mzero :: m a #

The identity of mplus. It should also satisfy the equations

mzero >>= f  =  mzero
v >> mzero   =  mzero

The default definition is

mzero = empty

mplus :: m a -> m a -> m a #

An associative operation. The default definition is

mplus = (<|>)

Instances

Instances details
MonadPlus []

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

mzero :: [a] #

mplus :: [a] -> [a] -> [a] #

MonadPlus Maybe

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

mzero :: Maybe a #

mplus :: Maybe a -> Maybe a -> Maybe a #

MonadPlus IO

Since: base-4.9.0.0

Instance details

Defined in GHC.Base

Methods

mzero :: IO a #

mplus :: IO a -> IO a -> IO a #

MonadPlus Option

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup

Methods

mzero :: Option a #

mplus :: Option a -> Option a -> Option a #

MonadPlus ReadP

Since: base-2.1

Instance details

Defined in Text.ParserCombinators.ReadP

Methods

mzero :: ReadP a #

mplus :: ReadP a -> ReadP a -> ReadP a #

MonadPlus P

Since: base-2.1

Instance details

Defined in Text.ParserCombinators.ReadP

Methods

mzero :: P a #

mplus :: P a -> P a -> P a #

MonadPlus (U1 :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

mzero :: U1 a #

mplus :: U1 a -> U1 a -> U1 a #

(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a)

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

mzero :: ArrowMonad a a0 #

mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 #

MonadPlus (Proxy :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in Data.Proxy

Methods

mzero :: Proxy a #

mplus :: Proxy a -> Proxy a -> Proxy a #

Monad m => MonadPlus (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

mzero :: MaybeT m a #

mplus :: MaybeT m a -> MaybeT m a -> MaybeT m a #

MonadPlus m => MonadPlus (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Printing

Methods

mzero :: TraceC m a #

mplus :: TraceC m a -> TraceC m a -> TraceC m a #

MonadPlus m => MonadPlus (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Ignoring

Methods

mzero :: TraceC m a #

mplus :: TraceC m a -> TraceC m a -> TraceC m a #

(Alternative m, Monad m) => MonadPlus (TraceC m) Source # 
Instance details

Defined in Control.Carrier.Trace.Returning

Methods

mzero :: TraceC m a #

mplus :: TraceC m a -> TraceC m a -> TraceC m a #

MonadPlus (NonDetC m) Source # 
Instance details

Defined in Control.Carrier.NonDet.Church

Methods

mzero :: NonDetC m a #

mplus :: NonDetC m a -> NonDetC m a -> NonDetC m a #

MonadPlus m => MonadPlus (LiftC m) Source # 
Instance details

Defined in Control.Carrier.Lift

Methods

mzero :: LiftC m a #

mplus :: LiftC m a -> LiftC m a -> LiftC m a #

(Alternative m, Monad m) => MonadPlus (FreshC m) Source # 
Instance details

Defined in Control.Carrier.Fresh.Strict

Methods

mzero :: FreshC m a #

mplus :: FreshC m a -> FreshC m a -> FreshC m a #

(Alternative m, Monad m) => MonadPlus (FailC m) Source # 
Instance details

Defined in Control.Carrier.Fail.Either

Methods

mzero :: FailC m a #

mplus :: FailC m a -> FailC m a -> FailC m a #

MonadPlus (CutC m) Source # 
Instance details

Defined in Control.Carrier.Cut.Church

Methods

mzero :: CutC m a #

mplus :: CutC m a -> CutC m a -> CutC m a #

MonadPlus (CullC m) Source # 
Instance details

Defined in Control.Carrier.Cull.Church

Methods

mzero :: CullC m a #

mplus :: CullC m a -> CullC m a -> CullC m a #

MonadPlus f => MonadPlus (Rec1 f)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

mzero :: Rec1 f a #

mplus :: Rec1 f a -> Rec1 f a -> Rec1 f a #

MonadPlus f => MonadPlus (Ap f)

Since: base-4.12.0.0

Instance details

Defined in Data.Monoid

Methods

mzero :: Ap f a #

mplus :: Ap f a -> Ap f a -> Ap f a #

MonadPlus f => MonadPlus (Alt f)

Since: base-4.8.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

mzero :: Alt f a #

mplus :: Alt f a -> Alt f a -> Alt f a #

(Monoid w, MonadPlus m) => MonadPlus (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.Strict

Methods

mzero :: WriterT w m a #

mplus :: WriterT w m a -> WriterT w m a -> WriterT w m a #

(Monoid w, MonadPlus m) => MonadPlus (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

Methods

mzero :: WriterT w m a #

mplus :: WriterT w m a -> WriterT w m a -> WriterT w m a #

MonadPlus m => MonadPlus (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Strict

Methods

mzero :: StateT s m a #

mplus :: StateT s m a -> StateT s m a -> StateT s m a #

MonadPlus m => MonadPlus (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

mzero :: StateT s m a #

mplus :: StateT s m a -> StateT s m a -> StateT s m a #

MonadPlus m => MonadPlus (ReaderT r m) 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

mzero :: ReaderT r m a #

mplus :: ReaderT r m a -> ReaderT r m a -> ReaderT r m a #

MonadPlus m => MonadPlus (IdentityT m) 
Instance details

Defined in Control.Monad.Trans.Identity

Methods

mzero :: IdentityT m a #

mplus :: IdentityT m a -> IdentityT m a -> IdentityT m a #

(Monad m, Monoid e) => MonadPlus (ExceptT e m) 
Instance details

Defined in Control.Monad.Trans.Except

Methods

mzero :: ExceptT e m a #

mplus :: ExceptT e m a -> ExceptT e m a -> ExceptT e m a #

(Alternative m, Monad m) => MonadPlus (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.Strict

Methods

mzero :: StateC s m a #

mplus :: StateC s m a -> StateC s m a -> StateC s m a #

(Alternative m, Monad m) => MonadPlus (WriterC w m) Source # 
Instance details

Defined in Control.Carrier.Writer.Strict

Methods

mzero :: WriterC w m a #

mplus :: WriterC w m a -> WriterC w m a -> WriterC w m a #

(Alternative m, Monad m) => MonadPlus (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.Lazy

Methods

mzero :: StateC s m a #

mplus :: StateC s m a -> StateC s m a -> StateC s m a #

(Alternative m, Monad m) => MonadPlus (ReaderC r m) Source # 
Instance details

Defined in Control.Carrier.Reader

Methods

mzero :: ReaderC r m a #

mplus :: ReaderC r m a -> ReaderC r m a -> ReaderC r m a #

(Alternative m, Monad m) => MonadPlus (ErrorC e m) Source #

ErrorC passes MonadPlus operations along to the underlying monad m, rather than combining errors à la ExceptT.

Instance details

Defined in Control.Carrier.Error.Either

Methods

mzero :: ErrorC e m a #

mplus :: ErrorC e m a -> ErrorC e m a -> ErrorC e m a #

(Alternative m, Monad m) => MonadPlus (ThrowC e m) Source # 
Instance details

Defined in Control.Carrier.Throw.Either

Methods

mzero :: ThrowC e m a #

mplus :: ThrowC e m a -> ThrowC e m a -> ThrowC e m a #

(MonadPlus f, MonadPlus g) => MonadPlus (f :*: g)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

mzero :: (f :*: g) a #

mplus :: (f :*: g) a -> (f :*: g) a -> (f :*: g) a #

(MonadPlus f, MonadPlus g) => MonadPlus (Product f g)

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Product

Methods

mzero :: Product f g a #

mplus :: Product f g a -> Product f g a -> Product f g a #

MonadPlus m => MonadPlus (InterpretC s sig m) Source # 
Instance details

Defined in Control.Carrier.Interpret

Methods

mzero :: InterpretC s sig m a #

mplus :: InterpretC s sig m a -> InterpretC s sig m a -> InterpretC s sig m a #

MonadPlus f => MonadPlus (M1 i c f)

Since: base-4.9.0.0

Instance details

Defined in GHC.Generics

Methods

mzero :: M1 i c f a #

mplus :: M1 i c f a -> M1 i c f a -> M1 i c f a #

(Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) 
Instance details

Defined in Control.Monad.Trans.RWS.Strict

Methods

mzero :: RWST r w s m a #

mplus :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

(Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) 
Instance details

Defined in Control.Monad.Trans.RWS.Lazy

Methods

mzero :: RWST r w s m a #

mplus :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

MonadPlus m => MonadPlus (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

mzero :: UnderLabel label sub m a #

mplus :: UnderLabel label sub m a -> UnderLabel label sub m a -> UnderLabel label sub m a #

MonadPlus (sub m) => MonadPlus (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

mzero :: Labelled label sub m a #

mplus :: Labelled label sub m a -> Labelled label sub m a -> Labelled label sub m a #

guard :: Alternative f => Bool -> f () #

Conditional failure of Alternative computations. Defined by

guard True  = pure ()
guard False = empty

Examples

Expand

Common uses of guard include conditionally signaling an error in an error monad and conditionally rejecting the current choice in an Alternative-based parser.

As an example of signaling an error in the error monad Maybe, consider a safe division function safeDiv x y that returns Nothing when the denominator y is zero and Just (x `div` y) otherwise. For example:

>>> safeDiv 4 0
Nothing
>>> safeDiv 4 2
Just 2

A definition of safeDiv using guards, but not guard:

safeDiv :: Int -> Int -> Maybe Int
safeDiv x y | y /= 0    = Just (x `div` y)
            | otherwise = Nothing

A definition of safeDiv using guard and Monad do-notation:

safeDiv :: Int -> Int -> Maybe Int
safeDiv x y = do
  guard (y /= 0)
  return (x `div` y)

optional :: Alternative f => f a -> f (Maybe a) #

One or none.

run :: Identity a -> a Source #

Run an action exhausted of effects to produce its final result value.

Since: 1.0.0.0