Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Alt m a where
- class Applicative f => Alternative (f :: Type -> Type) where
- runAltMaybe :: forall m a p. (Threaders '[ErrorThreads] m p, Carrier m) => AltMaybeC m a -> m (Maybe a)
- altToError :: forall e m a. Eff (Error e) m => e -> InterpretAltReifiedC m a -> m a
- altToNonDet :: Eff NonDet m => AltToNonDetC m a -> m a
- altToErrorSimple :: forall e m a p. (Eff (Error e) m, Threaders '[ReaderThreads] m p) => e -> InterpretAltSimpleC m a -> m a
- class (forall e. Threads (ExceptT e) p) => ErrorThreads p
- type AltMaybeC = CompositionC '[IntroUnderC Alt '[Catch (), Throw ()], InterpretAltC AltToErrorUnitH, ErrorC ()]
- newtype InterpretAltC h m a = InterpretAltC {
- unInterpretAltC :: InterpretC h Alt m a
- type InterpretAltReifiedC m a = forall s. ReifiesHandler s Alt m => InterpretAltC (ViaReifiedH s) m a
- type AltToNonDetC = InterpretAltC AltToNonDetH
- newtype InterpretAltSimpleC m a = InterpretAltSimpleC {}
Effects
An effect corresponding to the
Alternative
type class.
Effly'
s Alternative
instance
is based on this effect; by having access to Alt
, you're able to use
<|>
and empty
inside of effect
handlers.
Each Alt
interpreter's associated carrier
has an Alternative
instance based on
how it interprets Alt
. This means you can use
an Alt
interpreter to locally gain access to an Alternative
instance inside of application code.
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:
The identity of <|>
(<|>) :: f a -> f a -> f a infixl 3 #
An associative binary operation
One or more.
Zero or more.
Instances
Interpretations
runAltMaybe :: forall m a p. (Threaders '[ErrorThreads] m p, Carrier m) => AltMaybeC m a -> m (Maybe a) Source #
altToError :: forall e m a. Eff (Error e) m => e -> InterpretAltReifiedC m a -> m a Source #
Transform an Alt
effect into Error
by describing it in
terms of throw
and catch
, using the provided exception to act as empty
.
You can use this in application code to locally get access to an Alternative
instance (since InterpretAltReifiedC
has an Alternative
instance based
on the Alt
effect this interprets).
For example:
altToError
(throw
exc)empty
=throw
exc
altToError
has a higher-rank type, as it makes use of InterpretAltReifiedC
.
This makes altToError
very difficult to use partially applied.
In particular, it can't be composed using
..
If performance is secondary, consider using the slower altToErrorSimple
,
which doesn't have a higher-rank type. However, you typically don't
want to use altToErrorSimple
in application code, since altToErrorSimple
emits a ReaderThreads
threading constraint (see Threaders
).
altToNonDet :: Eff NonDet m => AltToNonDetC m a -> m a Source #
Transform an Alt
effect into NonDet
by describing it
in terms of lose
and choose
.
You can use this in application code to locally get access to an Alternative
instance (since AltToNonDetC
has an Alternative
instance based
on the Alt
effect this interprets).
For example:
altToNonDet
empty
=lose
Simple variants of interpretations
altToErrorSimple :: forall e m a p. (Eff (Error e) m, Threaders '[ReaderThreads] m p) => e -> InterpretAltSimpleC m a -> m a Source #
Transform an Alt
in terms of throw
and catch
, by providing an
exception to act as empty
.
This is a less performant version of altToError
that doesn't have
a higher-rank type, making it much easier to use partially applied.
Unlike altToError
, you typically don't want to use this in
application code, since this emits a ReaderThreads
threading constraint (see Threaders
).
Threading constraints
class (forall e. Threads (ExceptT e) p) => ErrorThreads p Source #
ErrorThreads
accepts the following primitive effects:
Regional
s
Optional
s
(whens
is a functor)BaseControl
b
Unravel
p
ListenPrim
s
(whens
is aMonoid
)WriterPrim
s
(whens
is aMonoid
)ReaderPrim
i
Mask
Bracket
Fix
Instances
(forall e. Threads (ExceptT e) p) => ErrorThreads p Source # | |
Defined in Control.Effect.Internal.Error |
Carriers
type AltMaybeC = CompositionC '[IntroUnderC Alt '[Catch (), Throw ()], InterpretAltC AltToErrorUnitH, ErrorC ()] Source #
newtype InterpretAltC h m a Source #
Like InterpretC specialized to interpret Alt
, but has Alternative
and
MonadPlus
instances based on the interpreted Alt
.
InterpretAltC | |
|
Instances
type InterpretAltReifiedC m a = forall s. ReifiesHandler s Alt m => InterpretAltC (ViaReifiedH s) m a Source #
type AltToNonDetC = InterpretAltC AltToNonDetH Source #
newtype InterpretAltSimpleC m a Source #