Copyright | (c) 2016 Allele Dev; 2017 Ixperta Solutions s.r.o. |
---|---|
License | BSD3 |
Maintainer | ixcom-core@ixperta.com |
Stability | experimental |
Portability | GHC specific language extensions. |
Safe Haskell | None |
Language | Haskell2010 |
- data Eff effs a
- class FindElem t r => Member t r
- type family Members m r :: Constraint where ...
- send :: Member eff effs => eff a -> Eff effs a
- type Arr effs a b = a -> Eff effs b
- run :: Eff '[] a -> a
- runM :: Monad m => Eff '[m] a -> m a
- runNat :: Member m effs => (forall a. eff a -> m a) -> Eff (eff ': effs) b -> Eff effs b
- runNatS :: Member m effs => s -> (forall a. s -> eff a -> m (s, a)) -> Eff (eff ': effs) b -> Eff effs b
- handleRelay :: (a -> Eff effs b) -> (forall v. eff v -> Arr effs v b -> Eff effs b) -> Eff (eff ': effs) a -> Eff effs b
- handleRelayS :: s -> (s -> a -> Eff effs b) -> (forall v. s -> eff v -> (s -> Arr effs v b) -> Eff effs b) -> Eff (eff ': effs) a -> Eff effs b
Effect Monad
The Eff monad provides a way to use effects in Haskell, in such a way that different types of effects can be interleaved, and so that the produced code is efficient.
Effect Constraints
type family Members m r :: Constraint where ... Source #
Sending Arbitrary Effect
Handling Effects
type Arr effs a b = a -> Eff effs b Source #
Effectful arrow type: a function from a :: *
to b :: *
that also does
effects denoted by effs :: [* -> *]
.
run :: Eff '[] a -> a Source #
Runs a set of Effects. Requires that all effects are consumed. Typically composed as follows:
run
. runEff1 eff1Arg . runEff2 eff2Arg1 eff2Arg2 $ someProgram
runM :: Monad m => Eff '[m] a -> m a Source #
Runs a set of Effects. Requires that all effects are consumed, except for a single effect known to be a monad. The value returned is a computation in that monad. This is useful for plugging in traditional transformer stacks.
Building Effect Handlers
runNat :: Member m effs => (forall a. eff a -> m a) -> Eff (eff ': effs) b -> Eff effs b Source #
Variant of handleRelay
simplified for the common case.
runNatS :: Member m effs => s -> (forall a. s -> eff a -> m (s, a)) -> Eff (eff ': effs) b -> Eff effs b Source #
Variant of handleRelayS
simplified for the common case.
:: (a -> Eff effs b) | Handle a pure value. |
-> (forall v. eff v -> Arr effs v b -> Eff effs b) | Handle a request for effect of type |
-> Eff (eff ': effs) a | |
-> Eff effs b | Result with effects of type |
Given a request, either handle it or relay it.
:: s | |
-> (s -> a -> Eff effs b) | Handle a pure value. |
-> (forall v. s -> eff v -> (s -> Arr effs v b) -> Eff effs b) | Handle a request for effect of type |
-> Eff (eff ': effs) a | |
-> Eff effs b | Result with effects of type |
Parameterized handleRelay
. Allows sending along some state of type
s :: *
to be handled for the target effect, or relayed to a handler that
can- handle the target effect.