-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | IoC Monad in Haskell -- -- Inverse of control monad used in building large application. @package boots @version 0.1 -- | IoC Monad in Haskell. -- --
-- factory = do
-- log <- logFactory
-- conf <- confFactory
-- within (log, conf) $ do
-- a <- withFactory fst aFactory
-- b <- withFactory snd bFactory
-- polish AB{..}
-- [ xFactory
-- , yFactory
-- ] >>> bootFactory
--
module Boots.Factory
-- | Factory defines how to generate a component under the
-- environment env in monad m. It is similar to IoC
-- container in oop, env will provide anything to be wanted to
-- generate component.
data Factory m env component
-- | Running the factory.
running :: env -> Factory m env c -> (c -> m ()) -> m ()
-- | Run the application using a specified factory.
boot :: Monad m => Factory m () (m ()) -> m ()
-- | Switch factory environment.
withFactory :: (env' -> env) -> Factory m env component -> Factory m env' component
-- | Construct factory under env, and adapt it to fit another
-- env'.
within :: env -> Factory m env component -> Factory m env' component
-- | Polish component by a sequence of Factory, and
-- construct a unified one.
polish :: component -> [Factory m component component] -> Factory m env' component
-- | Nature transform of one Factory with monad n into
-- another with monad m.
natTrans :: (n () -> m ()) -> (m () -> n ()) -> Factory n env component -> Factory m env component
-- | Wrap raw procedure into a Factory.
wrap :: ((c -> m ()) -> m ()) -> Factory m env c
-- | Construct open-close resource into a Factory.
bracket :: MonadCatch m => m res -> (res -> m ()) -> Factory m env res
-- | Lift a monad m into a Factory.
offer :: Monad m => m a -> Factory m env a
-- | Put a delay action into Factory, it will run at close phase.
delay :: MonadCatch m => m () -> Factory m env ()
-- | Left-to-right composition
(>>>) :: Category cat => cat a b -> cat b c -> cat a c
infixr 1 >>>
-- | Right-to-left composition
(<<<) :: Category cat => cat b c -> cat a b -> cat a c
infixr 1 <<<
-- | An associative operation.
(<>) :: Semigroup a => a -> a -> a
infixr 6 <>
-- | A class for monads in which exceptions may be thrown.
--
-- Instances should obey the following law:
--
-- -- throwM e >> x = throwM e ---- -- In other words, throwing an exception short-circuits the rest of the -- monadic computation. class Monad m => MonadThrow (m :: Type -> Type) -- | Throw an exception. Note that this throws when this action is run in -- the monad m, not when it is applied. It is a generalization -- of Control.Exception's throwIO. -- -- Should satisfy the law: -- --
-- throwM e >> f = throwM e --throwM :: (MonadThrow m, Exception e) => e -> m a -- | A class for monads which allow exceptions to be caught, in particular -- exceptions which were thrown by throwM. -- -- Instances should obey the following law: -- --
-- catch (throwM e) f = f e ---- -- Note that the ability to catch an exception does not guarantee -- that we can deal with all possible exit points from a computation. -- Some monads, such as continuation-based stacks, allow for more than -- just a success/failure strategy, and therefore catch -- cannot be used by those monads to properly implement a function -- such as finally. For more information, see MonadMask. class MonadThrow m => MonadCatch (m :: Type -> Type) -- | See examples in Control.Monad.Reader. Note, the partially -- applied function type (->) r is a simple reader monad. See -- the instance declaration below. class Monad m => MonadReader r (m :: Type -> Type) | m -> r -- | Retrieves the monad environment. ask :: MonadReader r m => m r -- | Executes a computation in a modified environment. local :: MonadReader r m => (r -> r) -> m a -> m a -- | Retrieves a function of the current environment. reader :: MonadReader r m => (r -> a) -> m a -- | Retrieves a function of the current environment. asks :: MonadReader r m => (r -> a) -> m a -- | Monads in which IO computations may be embedded. Any monad -- built by applying a sequence of monad transformers to the IO -- monad will be an instance of this class. -- -- Instances should satisfy the following laws, which state that -- liftIO is a transformer of monads: -- -- class Monad m => MonadIO (m :: Type -> Type) -- | Lift a computation from the IO monad. liftIO :: MonadIO m => IO a -> m a -- | Lift a computation from the argument monad to the constructed monad. lift :: (MonadTrans t, Monad m) => m a -> t m a instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Boots.Factory.Factory m env) instance Control.Monad.Reader.Class.MonadReader env (Boots.Factory.Factory m env) instance GHC.Base.Monad (Boots.Factory.Factory m env) instance GHC.Base.Applicative (Boots.Factory.Factory m env) instance GHC.Base.Functor (Boots.Factory.Factory m env) instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (Boots.Factory.Factory m env) instance GHC.Base.Monad m => Control.Monad.Cont.Class.MonadCont (Boots.Factory.Factory m env) instance GHC.Base.Semigroup (Boots.Factory.Factory m env env) instance GHC.Base.Monoid (Boots.Factory.Factory m env env) instance Control.Category.Category (Boots.Factory.Factory m)