extensible-effects-2.4.0.0: An Alternative to Monad Transformers

Safe HaskellSafe
LanguageHaskell2010

Control.Eff.Operational

Contents

Description

Operational Monad (https://wiki.haskell.org/Operational) implemented with extensible effects.

Synopsis

Documentation

data Program instr v where Source #

Lift values to an effect. You can think this is a generalization of Lift.

Constructors

Singleton :: instr a -> Program instr a 

singleton :: Member (Program instr) r => instr a -> Eff r a Source #

Lift a value to a monad.

runProgram :: forall f r 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