Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Optional s m a where
- Optionally :: s a -> m a -> Optional s m a
- threadRegionalViaOptional :: (ThreadsEff t (Optional (Const s)), Monad m) => (forall x. Regional s m x -> m x) -> Regional s (t m) a -> t m a
Effects
data Optional s m a where Source #
A helper primitive effect for manipulating a region, with the option
to execute it in full or in part. s
is expected to be a functor.
Helper primitive effects are effects that allow you to avoid interpreting one
of your own effects as a primitive if the power needed from direct access to
the underlying monad can instead be provided by the relevant helper primitive
effect. The reason why you'd want to do this is that helper primitive effects
already have ThreadsEff
instances defined for them, so you don't have to
define any for your own effect.
The helper primitive effects offered in this library are -- in order of
ascending power -- Regional
,
Optional
, BaseControl
and Unlift
.
The typical use-case of Optional
is to lift a natural transformation
of a base monad equipped with the power to recover from an exception.
HoistOption
and accompanying interpreters is
provided as a specialization of Optional
for this purpose.
Optional
in its most general form lacks a pre-defined interpreter:
when not using HoistOption
, you're expected to
define your own interpreter for Optional
(treating it as a primitive effect).
Optional
is typically used as a primitive effect.
If you define a Carrier
that relies on a novel
non-trivial monad transformer t
, then you need to make
a Functor s =>
instance (if possible).
ThreadsEff
t (Optional
s)threadOptionalViaBaseControl
can help you with that.
The following threading constraints accept Optional
:
Optionally :: s a -> m a -> Optional s m a |
Instances
Carrier m => PrimHandler HoistOptionH (HoistOption m) m Source # | |
Defined in Control.Effect.Internal.Optional effPrimHandler :: EffPrimHandler (HoistOption m) m Source # | |
Functor s => ThreadsEff ListT (Optional s) Source # | |
Functor s => ThreadsEff (ExceptT e) (Optional s) Source # | |
(Functor s, Monoid w) => ThreadsEff (WriterT w) (Optional s) Source # | |
Functor s => ThreadsEff (StateT s') (Optional s) Source # | |
ThreadsEff (ReaderT i) (Optional s) Source # | |
Functor s => ThreadsEff (StateT s') (Optional s) Source # | |
(Functor s, Monoid w) => ThreadsEff (WriterT w) (Optional s) Source # | |
(Functor s, Monoid w) => ThreadsEff (WriterT w) (Optional s) Source # | |
Functor s => ThreadsEff (FreeT f) (Optional s) Source # | |
Threading utilities
threadRegionalViaOptional :: (ThreadsEff t (Optional (Const s)), Monad m) => (forall x. Regional s m x -> m x) -> Regional s (t m) a -> t m a Source #
A valid definition of threadEff
for a
instance,
given that ThreadsEff
(Regional
s) tt
threads
for any functor Optional
ff
.