-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A library for writing Imperative style haskell. -- -- A monad that uses GADTs and continuations to replicate what it is like -- to program in an imperative language like C or Java with -- return, for, break, continue, and mutable -- references. @package ImperativeHaskell @version 1.1.1.0 -- | A module which defines the monad for ImperativeHaskell, and some -- control operator to interact with MIO module Control.Monad.Imperative.Internals -- | modifyOp makes a modification assignment operator out -- of a binary haskell function. The suggested use is to replicate -- functionality of assignments like -= or %= from C -- style languages. modifyOp :: ValTp k => (a -> b -> a) -> V Var r a -> V k r b -> MIO r () -- | if'(check) act only performs act if -- check evaluates to true it is specifically a value in its -- argument. if' :: ValTp b => V b r Bool -> MIO r () -> MIO r () -- | for'(init, check, incr) acts like its imperative -- for counterpart for' :: ValTp b => (MIO r irr1, V b r Bool, MIO r irr2) -> MIO r () -> MIO r () -- | while'(check) acts like its imperative while -- counterpart. while' :: ValTp b => V b r Bool -> MIO r () -> MIO r () -- | break' exists the current loop. if called outside of a -- loop, rather than throwing a compilation error, it will simply return -- a runtime error. break' :: MIO a () -- | continue' continues the current loop, passing over any control -- flow that is defined. if called outside of a loop, rather than -- throwing a compilation error, it will simply return a runtime error. continue' :: MIO a () -- | return' can act as returnF or returnV depending on use -- if it does not work, it is likely that type inference could not figure -- out a sensible alternative. return' :: (Returnable b r, ValTp a) => V a b b -> MIO b r -- | returnV value acts like the imperative return, where -- if called, it will exit the current function and place the returned -- value into the current continuation. Note, this doesn't work as a last -- function call. returnV :: ValTp a => V a b b -> MIO b () -- | returnF value acts like the imperative return, where -- if called, it will exit the current function and place the returned -- value into the current continuation. Note, this doesn't work inside of -- loops. Inside of loops, we need returnV returnF :: ValTp a => V a b b -> MIO b b -- | function foo takes an ImperativeMonad action and -- removes it from it's specific function context, specifically making it -- applicable in the body of other functions. function :: MIO a a -> MIO b a -- | new constructs a new reference to the specified pure value new :: a -> MIO r (V Var r a) -- | auto should just be used where the type can be automatically -- infered and we don't need an initial value Use caution, as it is -- simply an alternate name for undefined auto :: a runImperative :: MIO a a -> IO a data V b r a Lit :: a -> V Val r a C :: MIO r (V b r a) -> V Comp r a class ValTp b data MIO r a data Comp data Val data Var -- | variable =: value executes value and writes -- it to the location pointed to by variable (=:) :: Assignable valt => V Var r a -> valt r a -> MIO r () -- | (&)a gets a reference/pointer to the variable -- specified (&) :: V Var r a -> V Var s a val :: ValTp b => V b r a -> MIO r a instance Monad (MIO r) instance MonadCont (MIO r) instance MonadIO (MIO r) instance Assignable MIO instance ValTp b => Assignable (V b) instance IsString s => IsString (V Val r s) instance Num a => Num (V Val r a) instance Show a => Show (V Val r a) instance Eq a => Eq (V Val r a) instance Returnable b b instance Returnable b () instance ValTp Comp instance ValTp Val instance ValTp Var -- | Some predefined operators for the imperative monad. module Control.Monad.Imperative.Operators (+=:, -=:, *=:) :: (ValTp k, Num b) => V Var r b -> V k r b -> MIO r () (%=:) :: (ValTp k, Integral b) => V Var r b -> V k r b -> MIO r () (<., <=., >=., >.) :: (ValTp b1, ValTp b2, Ord b) => V b1 r b -> V b2 r b -> V Comp r Bool (==.) :: (ValTp b1, ValTp b2, Eq b) => V b1 r b -> V b2 r b -> V Comp r Bool (+., *., -.) :: (ValTp b1, ValTp b2, Num c) => V b1 r c -> V b2 r c -> V Comp r c (%.) :: (ValTp b1, ValTp b2, Integral c) => V b1 r c -> V b2 r c -> V Comp r c (/.) :: (ValTp b1, ValTp b2, Fractional c) => V b1 r c -> V b2 r c -> V Comp r c (&&., ||.) :: (ValTp b1, ValTp b2) => V b1 r Bool -> V b2 r Bool -> V Comp r Bool (~.) :: ValTp b1 => V b1 r Bool -> V Comp r Bool -- | liftOp2 f turns a pure function into one which gets -- executes its arguments and returns their value as a function. It is -- defined using liftOp. liftOp2 :: (ValTp b1, ValTp b2) => (a -> b -> c) -> V b1 r a -> V b2 r b -> V Comp r c -- | A module which defines a function liftOp which coverts pure -- functions into reference taking functions. module Control.Monad.Imperative.FunctionFactory liftOp :: Name -> Q Exp -- | A front end for the ImperativeMonad module Control.Monad.Imperative