Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
A monadic library for implementing effectful computation in a modular way.
This module provides the Eff
monad - the base type for all effectful
computation.
The Member
typeclass is the main interface for describing which effects
are necessary for a given function.
Consult the Control.Eff.QuickStart
module and the readme for gentle
introductions.
To use extensible effects effectively some language extensions are necessary/recommended.
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MonoLocalBinds #-}
Synopsis
- run :: Eff '[] w -> w
- data Eff r a
- lift :: Lifted m r => m a -> Eff r a
- runLift :: Monad m => Eff '[Lift m] w -> m w
- catchDynE :: forall e a r. (Lifted IO r, Exception e) => Eff r a -> (e -> Eff r a) -> Eff r a
- data HandlerDynE r a = (Exception e, Lifted IO r) => HandlerDynE (e -> Eff r a)
- catchesDynE :: Lifted IO r => Eff r a -> [HandlerDynE r a] -> Eff r a
- newtype Lift m a = Lift {
- unLift :: m a
- type Lifted m r = SetMember Lift (Lift m) r
- type LiftedBase m r = (SetMember Lift (Lift m) r, MonadBaseControl m (Eff r))
- class FindElem t r => Member (t :: * -> *) r
- class Member t r => SetMember (tag :: k -> * -> *) (t :: * -> *) r | tag r -> t
- type family (ms :: [* -> *]) <:: r where ...
Effect type
run :: Eff '[] w -> w Source #
Get the result from a pure computation
A pure computation has type Eff '[] a
. The empty effect-list indicates that
no further effects need to be handled.
The monad that all effects in this library are based on.
An effectful computation is a value of type `Eff r a`.
In this signature, r
is a type-level list of effects that are being
requested and need to be handled inside an effectful computation.
a
is the computation's result similar to other monads.
A computation's result can be retrieved via the run
function.
However, all effects used in the computation need to be handled by the use
of the effects' run*
functions before unwrapping the final result.
For additional details, see the documentation of the effects you are using.
Instances
Lift IO computations
lift :: Lifted m r => m a -> Eff r a Source #
embed an operation of type `m a` into the Eff
monad when Lift m
is in
a part of the effect-list.
runLift :: Monad m => Eff '[Lift m] w -> m w Source #
The handler of Lift requests. It is meant to be terminal: we only allow a single Lifted Monad. Note, too, how this is different from other handlers.
catchDynE :: forall e a r. (Lifted IO r, Exception e) => Eff r a -> (e -> Eff r a) -> Eff r a Source #
Catching of dynamic exceptions See the problem in http://okmij.org/ftp/Haskell/misc.html#catch-MonadIO
data HandlerDynE r a Source #
You need this when using catches
.
(Exception e, Lifted IO r) => HandlerDynE (e -> Eff r a) |
catchesDynE :: Lifted IO r => Eff r a -> [HandlerDynE r a] -> Eff r a Source #
Catch multiple dynamic exceptions. The implementation follows that in Control.Exception almost exactly. Not yet tested. Could this be useful for control with cut?
Lifting: emulating monad transformers
type Lifted m r = SetMember Lift (Lift m) r Source #
A convenient alias to 'SetMember Lift (Lift m) r', which allows us to assert that the lifted type occurs ony once in the effect list.
type LiftedBase m r = (SetMember Lift (Lift m) r, MonadBaseControl m (Eff r)) Source #
Same as Lifted
but with additional MonadBaseControl
constraint
Effect list
class FindElem t r => Member (t :: * -> *) r Source #
Typeclass that asserts that effect t
is contained inside the effect-list
r
.
The FindElem
typeclass is an implementation detail and not required for
using the effect list or implementing custom effects.
Instances
FindElem t r => Member t r Source # | |
t ~ s => Member t (s ': ([] :: [Type -> Type])) Source # | Explicit type-level equality condition is a dirty
hack to eliminate the type annotation in the trivial case,
such as There is no ambiguity when finding instances for
The only case we have to concerned about is |