-- 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, and 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.2.0.2 -- | 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 documentation in -- docs/Documentation.html, also available at -- http://projects.haskell.org/operational/Documentation.html . -- -- This API reference includes only basic example code. More intricate -- examples are available in the docs/examples directory, also -- available at -- http://projects.haskell.org/operational/examples.html. 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 ProgramViewT.) type ProgramView instr a = ProgramViewT instr Identity a -- | View function for inspecting the first instruction. view :: Program instr a -> ProgramView instr a -- | The abstract data type ProgramT instr m a represents -- programs. -- -- -- -- ProgramT instr m is a monad transformer and -- automatically obeys both the monad and the lifting laws. data ProgramT instr m a -- | View type for inspecting the first instruction. data ProgramViewT instr m a Return :: a -> ProgramViewT instr m a (:>>=) :: instr b -> (b -> ProgramT instr m a) -> ProgramViewT instr m a -- | View function for inspecting the first instruction. viewT :: Monad m => ProgramT instr m a -> m (ProgramViewT instr m a) -- | Lift a plain sequence of instructions to a sequence of instructions -- over a monad m. This is the counterpart of the lift -- function from MonadTrans. -- -- It can be defined as follows: -- --
--   liftProgram = eval . view
--       where
--       eval :: ProgramView instr a -> ProgramT instr m a
--       eval (Return a) = return a
--       eval (i :>>= k) = singleton i >>= liftProgram . k
--   
liftProgram :: Monad m => Program instr a -> ProgramT instr m a instance MonadIO m => MonadIO (ProgramT instr m) instance MonadState s m => MonadState s (ProgramT instr m) 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)