| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Effect.Optional
Synopsis
- data Optional s :: Effect where
- Optionally :: s a -> m a -> Optional s m a
- type HoistOption (b :: * -> *) = Optional (HoistOptionCall b)
- newtype HoistOptionCall b a = HoistOptionCall (forall x. (a -> x) -> b x -> b x)
- optionally :: Eff (Optional s) m => s a -> m a -> m a
- hoistOption :: Eff (HoistOption b) m => (forall x. (a -> x) -> b x -> b x) -> m a -> m a
- runHoistOption :: Carrier m => HoistOptionC m a -> m a
- hoistOptionToFinal :: (MonadBaseControl b m, Carrier m) => HoistOptionToFinalC b m a -> m a
- threadOptionalViaBaseControl :: forall s t m a. (Functor s, Monad m, Monad (t m), ThreadsEff t (BaseControl m)) => (forall x. Optional s m x -> m x) -> Optional s (t m) a -> t m a
- powerAlgHoistOption :: forall m p a. Algebra' p m a -> Algebra' (HoistOption m ': p) m a
- powerAlgHoistOptionFinal :: forall b m p a. MonadBaseControl b m => Algebra' p m a -> Algebra' (HoistOption b ': p) m a
- data HoistOptionC m a
- type HoistOptionToFinalC b = InterpretPrimC HoistOptionToFinalH (HoistOption b)
Effects
data Optional s :: Effect 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:
Constructors
| Optionally :: s a -> m a -> Optional s m a |
Instances
| Functor s => ThreadsEff ListT (Optional s) Source # | |
| Carrier m => PrimHandler HoistOptionH (HoistOption m) m Source # | |
Defined in Control.Effect.Internal.Optional Methods effPrimHandler :: EffPrimHandler (HoistOption m) m Source # | |
| (MonadCatch m, Carrier m) => PrimHandler ErrorIOFinalH (Optional ((->) SomeException :: Type -> Type)) m Source # | |
Defined in Control.Effect.Internal.ErrorIO Methods effPrimHandler :: EffPrimHandler (Optional ((->) SomeException)) m 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 # | |
type HoistOption (b :: * -> *) = Optional (HoistOptionCall b) Source #
A useful specialization of Optional where the functor is
. From this, you can derive
HoistOptionCall bhoistOption.
newtype HoistOptionCall b a Source #
Constructors
| HoistOptionCall (forall x. (a -> x) -> b x -> b x) |
Instances
| Carrier m => PrimHandler HoistOptionH (HoistOption m) m Source # | |
Defined in Control.Effect.Internal.Optional Methods effPrimHandler :: EffPrimHandler (HoistOption m) m Source # | |
| Functor (HoistOptionCall b) Source # | |
Defined in Control.Effect.Internal.Optional Methods fmap :: (a -> b0) -> HoistOptionCall b a -> HoistOptionCall b b0 # (<$) :: a -> HoistOptionCall b b0 -> HoistOptionCall b a # | |
Actions
optionally :: Eff (Optional s) m => s a -> m a -> m a Source #
Execute the provided computation, providing the
interpretation of the option to execute
it in full or in part.Optional s
hoistOption :: Eff (HoistOption b) m => (forall x. (a -> x) -> b x -> b x) -> m a -> m a Source #
Hoist a natural transformation of the base monad into the current monad, equipped with the option to execute the provided computation in full or in part.
Interpretations
runHoistOption :: Carrier m => HoistOptionC m a -> m a Source #
Runs a effect, where the base monad
HoistOption mm is the current monad.
Derivs(HoistOptionCm) =HoistOptionm ':Derivsm
Prims(HoistOptionCm) =HoistOptionm ':Primsm
hoistOptionToFinal :: (MonadBaseControl b m, Carrier m) => HoistOptionToFinalC b m a -> m a Source #
Runs a effect, where the base monad
HoistOption bb is the final base monad.
Derivs(HoistOptionToFinalCb m) =HoistOptionb ':Derivsm
Prims(HoistOptionToFinalCb m) =HoistOptionb ':Primsm
Threading utilities
threadOptionalViaBaseControl :: forall s t m a. (Functor s, Monad m, Monad (t m), ThreadsEff t (BaseControl m)) => (forall x. Optional s m x -> m x) -> Optional s (t m) a -> t m a Source #
A valid definition of threadEff for a
instance, given that ThreadsEff t (Optional s)t threads for any BaseControl bb.
Combinators for Algebras
powerAlgHoistOption :: forall m p a. Algebra' p m a -> Algebra' (HoistOption m ': p) m a Source #
Strengthen an by adding a Algebra p m handlerHoistOption m
powerAlgHoistOptionFinal :: forall b m p a. MonadBaseControl b m => Algebra' p m a -> Algebra' (HoistOption b ': p) m a Source #
Strengthen an by adding a Algebra p m handler, where
HoistOption bb is the final base monad.
Carriers
data HoistOptionC m a Source #
Instances
type HoistOptionToFinalC b = InterpretPrimC HoistOptionToFinalH (HoistOption b) Source #