-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Implement monads by specifying operational semantics. -- -- Tiny library for implementing monads by specifying the primitive -- instructions and their operational semantics. The monad laws will hold -- automatically. Can also be used to define monad transformers, the -- lifting laws are, again, automatic. Accompanies the article: "The -- Operational Monad Tutorial", published in Issue 15 of The Monad.Reader -- http://themonadreader.wordpress.com/2010/01/26/issue-15/. -- Related packages: MonadPrompt -- http://hackage.haskell.org/package/MonadPrompt. @package operational @version 0.1.0.0 -- | Implement monads by specifying primitive instructions and their -- operational semantics. -- -- This package is based on the "The Operational Monad Tutorial", -- published in Issue 15 of The Monad.Reader -- http://themonadreader.wordpress.com/. -- -- You are reading the API reference. For more thorough documentation -- including design and implementation notes as well as a correctness -- proof, please consult the included doc/Documentation.html. -- -- This API reference includes only basic example code. More intricate -- examples are available in the doc/examples directory. module Control.Monad.Operational -- | The abstract data type 'Program instr a' represents programs. -- -- -- -- Program instr is always a monad and automatically -- obeys the monad laws. type Program instr a = ProgramT instr Identity a -- | Program made from a single primitive instruction. singleton :: instr a -> ProgramT instr m a -- | View type for inspecting the first instruction. It has two -- constructors Return and :>>=. (For technical -- reasons, they are documented at PromptT.) type Prompt instr a = PromptT instr Identity a -- | View function for inspecting the first instruction. view :: Program instr a -> Prompt instr a -- | The abstract data type ProgramT instr m a represents -- programs. -- -- -- -- ProgramT instr m is a monad transformer and -- automatically obey both the monad and the lifting laws. data ProgramT instr m a -- | View type for inspecting the first instruction. data PromptT instr m a Return :: a -> PromptT instr m a (:>>=) :: instr b -> (b -> ProgramT instr m a) -> PromptT instr m a -- | View function for inspecting the first instruction. viewT :: (Monad m) => ProgramT instr m a -> m (PromptT instr m a) instance (Monad m) => Applicative (ProgramT instr m) instance (Monad m) => Functor (ProgramT instr m) instance MonadTrans (ProgramT instr) instance (Monad m) => Monad (ProgramT instr m)