free-operational-0.5.0.0: Operational Applicative, Alternative, Monad and MonadPlus from free types.

Safe HaskellNone

Control.Monad.Operational

Description

A reconstruction of the operational package in terms of the FreeT monad transformer.

This module is meant to be a drop-in replacement for its counterpart in the operational package. Some of the implementation choices reflect that:

The ProgramT and ProgramViewT types and operations are reexported from Control.Monad.Trans.Operational.

Synopsis

Documentation

type Program instr = ProgramT instr IdentitySource

Drop-in replacement for operational's type synonym.

toFree :: Program instr a -> Free (Coyoneda instr) aSource

The Free monad action for a Program.

fromProgram :: (Operational instr m, Functor m, Monad m) => Program instr a -> m aSource

Lift a Program into any Operational type at least as strong as Monad.

liftProgram :: Monad m => Program instr a -> ProgramT instr m aSource

Lift a Program into a ProgramT. Really the same as fromProgram, but with a more restricted type; this function is a drop-in replacement for the eponymous function in operational.

interpret :: forall m instr a. (Functor m, Monad m) => (forall x. instr x -> m x) -> Program instr a -> m aSource

Interpret a Program by interpreting each instruction as a monadic action. Unlike interpretWithMonad, this soes not use view nor ProgramView.

This function is not a drop-in replacement for interpretWithMonad because it has an extra Functor m constraint.

interpretWithMonad :: Monad m => (forall x. instr x -> m x) -> Program instr a -> m aSource

Drop-in replacement for the eponymous function in the operational package. This is like interpret but with a slightly broader type, and the same implementation as in operational (in terms of view).

type ProgramView instr = ProgramViewT instr IdentitySource

Drop-in replacement for operational's eponymous type synonym.

view :: Program instr a -> ProgramView instr aSource

Drop-in replacement for operational's function.