Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Control.Eff.Operational
Contents
Description
Operational Monad (https://wiki.haskell.org/Operational) implemented with extensible effects.
Synopsis
- data Program (instr :: k -> Type) (v :: k) where
- withOperational :: forall a (f :: Type -> Type) (r :: [Type -> Type]). a -> Intrprtr f r -> Eff r a
- newtype Intrprtr (f :: Type -> Type) (r :: [Type -> Type]) = Intrprtr {
- runIntrprtr :: forall x. f x -> Eff r x
- singleton :: forall instr (r :: [Type -> Type]) a. Member (Program instr) r => instr a -> Eff r a
- runProgram :: forall f (r :: [Type -> Type]) a. (forall x. f x -> Eff r x) -> Eff (Program f ': r) a -> Eff r a
Documentation
data Program (instr :: k -> Type) (v :: k) where Source #
Lift values to an effect.
You can think this is a generalization of Lift
.
Instances
Handle (Program f) r a (Intrprtr f r' -> Eff r' a) Source # | Given a continuation and a program, interpret it
Usually, we have |
Defined in Control.Eff.Operational Methods handle :: (Eff r a -> Intrprtr f r' -> Eff r' a) -> Arrs r v a -> Program f v -> Intrprtr f r' -> Eff r' a Source # handle_relay :: forall (r'0 :: [Type -> Type]). (r ~ (Program f ': r'0), Relay (Intrprtr f r' -> Eff r' a) r'0) => (a -> Intrprtr f r' -> Eff r' a) -> (Eff r a -> Intrprtr f r' -> Eff r' a) -> Eff r a -> Intrprtr f r' -> Eff r' a Source # respond_relay :: (a -> Intrprtr f r' -> Eff r' a) -> (Eff r a -> Intrprtr f r' -> Eff r' a) -> Eff r a -> Intrprtr f r' -> Eff r' a Source # |
withOperational :: forall a (f :: Type -> Type) (r :: [Type -> Type]). a -> Intrprtr f r -> Eff r a Source #
Embed a pure value
newtype Intrprtr (f :: Type -> Type) (r :: [Type -> Type]) Source #
General form of an interpreter
Constructors
Intrprtr | |
Fields
|
Instances
Handle (Program f) r a (Intrprtr f r' -> Eff r' a) Source # | Given a continuation and a program, interpret it
Usually, we have |
Defined in Control.Eff.Operational Methods handle :: (Eff r a -> Intrprtr f r' -> Eff r' a) -> Arrs r v a -> Program f v -> Intrprtr f r' -> Eff r' a Source # handle_relay :: forall (r'0 :: [Type -> Type]). (r ~ (Program f ': r'0), Relay (Intrprtr f r' -> Eff r' a) r'0) => (a -> Intrprtr f r' -> Eff r' a) -> (Eff r a -> Intrprtr f r' -> Eff r' a) -> Eff r a -> Intrprtr f r' -> Eff r' a Source # respond_relay :: (a -> Intrprtr f r' -> Eff r' a) -> (Eff r a -> Intrprtr f r' -> Eff r' a) -> Eff r a -> Intrprtr f r' -> Eff r' a Source # |
singleton :: forall instr (r :: [Type -> Type]) a. Member (Program instr) r => instr a -> Eff r a Source #
Lift a value to a monad.
runProgram :: forall f (r :: [Type -> Type]) a. (forall x. f x -> Eff r x) -> Eff (Program f ': r) a -> Eff r a Source #
Convert values using given interpreter to effects.
Usage
See Control.Eff.Operational.Example for an example of defining data using GADTs and implementing interpreters from the data to effects.
To use the interpreter, see below or consult the tests.
main :: IO () main = do let comp =runProgram
adventPure prog putStrLn . fst .run
.runMonoidWriter
$evalState
comp ["foo","bar"]runLift
$runProgram
adventIO prog