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

Control.Effect.Choose

Description

An effect modelling nondeterminism without failure (one or more successful results).

The NonDet effect is the composition of Choose and Empty.

Predefined carriers:

Since: 1.0.0.0

Synopsis

Choose effect

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.2-inplace" 'True) (C1 ('MetaCons "Choose" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (((->) Bool :: Type -> Type) :.: Rec1 m)))

(<|>) :: Has Choose sig m => m a -> m a -> m a infixl 3 Source #

Nondeterministically choose between two computations.

(m <|> n) >>= k = (m >>= k) <|> (n >>= k)
(m <|> n) <|> o = m <|> (n <|> o)
empty <|> m = m
m <|> empty = m

Since: 1.0.0.0

optional :: Has Choose sig m => m a -> m (Maybe a) Source #

Select between Just the result of an operation, and Nothing.

optional empty = pure Nothing
optional (pure a) = pure (Just a)

Since: 1.0.0.0

many :: Has Choose sig m => m a -> m [a] Source #

Zero or more.

many m = some m <|> pure []

Since: 1.0.0.0

some :: Has Choose sig m => m a -> m [a] Source #

One or more.

some m = (:) <$> m <*> many m

Since: 1.0.0.0

some1 :: Has Choose sig m => m a -> m (NonEmpty a) Source #

One or more, returning a NonEmpty list of the results.

some1 m = (:|) <$> m <*> many m

Since: 1.0.0.0

Choosing semigroup

newtype Choosing m a Source #

Since: 1.0.0.0

Constructors

Choosing 

Fields

Instances

Instances details
Has Choose sig m => Semigroup (Choosing m a) Source # 
Instance details

Defined in Control.Effect.Choose

Methods

(<>) :: Choosing m a -> Choosing m a -> Choosing m a #

sconcat :: NonEmpty (Choosing m a) -> Choosing m a #

stimes :: Integral b => b -> Choosing m a -> Choosing m a #

(Has Choose sig m, Has Empty sig m) => Monoid (Choosing m a) Source # 
Instance details

Defined in Control.Effect.Choose

Methods

mempty :: Choosing m a #

mappend :: Choosing m a -> Choosing m a -> Choosing m a #

mconcat :: [Choosing m a] -> Choosing m a #

Re-exports

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.

run :: Identity a -> a Source #

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

Since: 1.0.0.0