-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Implementation of difficult monads made easy -- with operational semantics. -- -- This library makes it easy to implement monads with tricky control -- flow. -- -- This is useful for: writing web applications in a sequential style, -- programming games with a uniform interface for human and AI players -- and easy replay capababilities, implementing fast parser monads, -- designing monadic DSLs, etc. -- -- See the project homepage http://wiki.haskell.org/Operational -- for a more detailed introduction and features. -- -- Related packages: MonadPrompt -- http://hackage.haskell.org/package/MonadPrompt. @package operational @version 0.2.3.4 module Control.Monad.Operational -- | The abstract data type Program instr a represents -- programs, i.e. sequences of primitive instructions. -- -- -- -- Program instr is always a monad and automatically -- obeys the monad laws. type Program instr = ProgramT instr Identity -- | 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 = ProgramViewT instr Identity -- | View function for inspecting the first instruction. view :: Program instr a -> ProgramView instr a -- | Utility function that extends a given interpretation of instructions -- as monadic actions to an interpration of Programs as monadic -- actions. -- -- This function can be useful if you are mainly interested in mapping a -- Program to different standard monads, like the state monad. For -- implementing a truly custom monad, you should write your interpreter -- directly with view instead. interpretWithMonad :: forall instr m b. Monad m => (forall a. instr a -> m a) -> (Program instr b -> m b) -- | The abstract data type ProgramT instr m a represents -- programs over a base monad m, i.e. sequences of primitive -- instructions and actions from the base monad. -- -- -- -- 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. This is very similar -- to pattern matching on lists. -- -- 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 GHC.Base.Monad m => GHC.Base.Monad (Control.Monad.Operational.ProgramT instr m) instance Control.Monad.Trans.Class.MonadTrans (Control.Monad.Operational.ProgramT instr) instance GHC.Base.Monad m => GHC.Base.Functor (Control.Monad.Operational.ProgramT instr m) instance GHC.Base.Monad m => GHC.Base.Applicative (Control.Monad.Operational.ProgramT instr m) instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Control.Monad.Operational.ProgramT instr m) instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Control.Monad.Operational.ProgramT instr m) instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Operational.ProgramT instr m)