Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class (forall x y a. Coercible (e (Program x) a) (e (Program y) a)) => Effect e
- newtype Program (es :: [(* -> *) -> * -> *]) a = Program {
- programToIO :: IO a
- class Member e es where
- type ProgramWithHandler e es a = forall s. HandlerInScope s e es => Program (Handled e s ': es) a
- interpret :: Effect e => (forall x. e (Program es) x -> Program es x) -> ProgramWithHandler e es a -> Program es a
- data Handled e s m a
- class HandlerInScope s e es | s -> e es
Documentation
newtype Program (es :: [(* -> *) -> * -> *]) a Source #
The Program
monad is where you will type your effectful programs. The
parameter es
is an effect list - the list of all possible effects that
your program has access to.
When writing computations in the Program
monad, you should keep es
polymorphic and add constraints using the Member
type class. For example,
prefer:
myApp :: Member HTTP es => Program es a
over
myApp :: Program ( HTTP : es ) a
as the former is much more composable.
Program | |
|
class Member e es where Source #
The Member e es
constraint witnesses that the effect e
can be found
in the effect list es
.
type ProgramWithHandler e es a = forall s. HandlerInScope s e es => Program (Handled e s ': es) a Source #
A ProgramWithHandler e es
computation similar to a normal
Program ( e : es)
computation, but with the added information that an
effect handler for e
is in scope.
You will typically not write programs with this type, but you will use it
whenever you provide an interpretation using interpret
.
:: Effect e | |
=> (forall x. e (Program es) x -> Program es x) | This function pattern matches on the effect signature |
-> ProgramWithHandler e es a | The program to supply this interpretation to. |
-> Program es a |
You provide an interpretation of an individual effect using interpret
.
A Handled
effect has the same capabilities as the effect e
, but this
provides evidence to GHC that an effect handler for this effect is in scope.
class HandlerInScope s e es | s -> e es Source #
reflect