-- 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, Java or Go with -- return, for, break, continue, and mutable -- references. -- -- In Version 2: -- -- -- -- For more information see: -- -- @package ImperativeHaskell @version 2.0.0.1 -- | 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 :: (HasValue r (V TyVar r) i, HasValue r (V k r) i) => (a -> b -> a) -> V TyVar r a -> V k r b -> MIO i r () -- | if'(check) act only performs act if -- check evaluates to true it is specifically a value in its -- argument. if' :: (HasValue r (V b r) i, HasValue r valt i) => V b r Bool -> valt () -> MIO i r () -- | for'(init, check, incr) acts like its imperative -- for counterpart for' :: (CState i, HasValue r (V b r) i, HasValue r valt TyInLoop) => (MIO i r irr1, V b r Bool, MIO i r irr2) -> valt () -> MIO i r () -- | while'(check) acts like its imperative while -- counterpart. while' :: (HasValue r (V b r) i, HasValue r (V b r) TyInLoop, HasValue r valt TyInLoop, CState i) => V b r Bool -> valt () -> MIO i r () -- | break' exists the current loop. break' :: MIO TyInLoop r () -- | continue' continues the current loop, passing over any control -- flow that is defined. continue' :: MIO TyInLoop r () -- | defer' executes the given action (or value) before the function -- returns. defer' :: HasValue r valt TyInFunc => valt a -> MIO i r () -- | 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 TyInFunc a a -> MIO i b a -- | new constructs a new reference to the specified pure value new :: HasValue r (V TyVar r) i => a -> MIO i r (V TyVar 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 takes an MIO action as returned by a -- function, and lifts it into IO. runImperative :: MIO TyInFunc a a -> IO a -- | io action takes a haskell IO action -- and makes it useable from within the MIO monad. io :: IO a -> MIO i r a data V b r a Lit :: a -> V TyVal r a C :: MIO i r (V b r a) -> V (TyComp i b) r a data MIO i r a data TyInLoop data TyInFunc data TyVar data TyVal data TyComp i v -- | variable =: value executes value and writes -- it to the location pointed to by variable (=:) :: (HasValue r valt i, HasValue r (V TyVar r) i) => V TyVar r a -> valt a -> MIO i r () -- | (&)a gets a reference/pointer to the variable -- specified (&) :: V TyVar r a -> V TyVar s a -- | Although the functional dependency b -> i is declared, it -- does not do anything useful. class HasValue r b i | b -> r i val :: HasValue r b i => b a -> MIO i r a class CState i return' :: (CState i, HasValue r (V a r) i) => V a r r -> MIO i r (RetTy i r) instance Monad (MIO i r) instance MonadCont (MIO i r) instance MonadIO (MIO i r) instance IsString s => IsString (V TyVal r s) instance Num a => Num (V TyVal r a) instance Show a => Show (V TyVal r a) instance Eq a => Eq (V TyVal r a) instance CState TyInLoop instance CState TyInFunc instance HasValue r IO i instance HasValue r (MIO i r) i instance HasValue r (V b r) a => HasValue r (V (TyComp a b) r) a instance HasValue r (V TyVal r) i instance HasValue r (V TyVar r) i -- | Some predefined operators for the imperative monad. module Control.Monad.Imperative.Operators (+=:, -=:, *=:) :: (HasValue r (V k r) i, Num b) => V TyVar r b -> V k r b -> MIO i r () (%=:) :: (HasValue r (V k r) i, Integral b) => V TyVar r b -> V k r b -> MIO i r () (<., <=., >=., >.) :: (Ord c, HasValue r (V b1 r) i, HasValue r (V b2 r) i) => V b1 r c -> V b2 r c -> V (TyComp i TyVal) r Bool (==.) :: (Eq c, HasValue r (V b1 r) i, HasValue r (V b2 r) i) => V b1 r c -> V b2 r c -> V (TyComp i TyVal) r Bool (+., *., -.) :: (Num c, HasValue r (V b1 r) i, HasValue r (V b2 r) i) => V b1 r c -> V b2 r c -> V (TyComp i TyVal) r c (%.) :: (Integral c, HasValue r (V b1 r) i, HasValue r (V b2 r) i) => V b1 r c -> V b2 r c -> V (TyComp i TyVal) r c (/.) :: (HasValue r (V b1 r) i, HasValue r (V b2 r) i, Fractional c) => V b1 r c -> V b2 r c -> V (TyComp i TyVal) r c (&&., ||.) :: (HasValue r (V b1 r) i, HasValue r (V b2 r) i) => V b1 r Bool -> V b2 r Bool -> V (TyComp i TyVal) r Bool (~.) :: HasValue r (V b r) i => V b r Bool -> V (TyComp i TyVal) 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 :: (HasValue r (V b1 r) i, HasValue r (V b2 r) i) => (a -> b -> c) -> V b1 r a -> V b2 r b -> V (TyComp i TyVal) 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