-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Parallel execution of monadic computations -- -- This package defines classes of monads that can perform multiple -- executions in parallel and combine their results. For any monad that's -- an instance of the class, the package re-implements a subset of the -- Control.Monad interface, but with parallel execution. @package monad-parallel @version 0.7 -- | This module defines classes of monads that can perform multiple -- computations in parallel and, more importantly, combine the results of -- those parallel computations. -- -- There are two classes exported by this module, MonadParallel -- and MonadFork. The former is more generic, but the latter is -- easier to use: when invoking any expensive computation that could be -- performed in parallel, simply wrap the call in forkExec. The -- function immediately returns a handle to the running computation. The -- handle can be used to obtain the result of the computation when -- needed: -- --
-- do child <- forkExec expensive -- otherStuff -- result <- child ---- -- In this example, the computations expensive and -- otherStuff would be performed in parallel. When using the -- MonadParallel class, both parallel computations must be -- specified at once: -- --
-- bindM2 (\ childResult otherResult -> ...) expensive otherStuff ---- -- In either case, for best results the costs of the two computations -- should be roughly equal. -- -- Any monad that is an instance of the MonadFork class is also an -- instance of the MonadParallel class, and the following law -- should hold: -- --
-- bindM2 f ma mb = do {a' <- forkExec ma; b <- mb; a <- a'; f a b}
--
--
-- When operating with monads free of side-effects, such as
-- Identity or Maybe, forkExec is equivalent to
-- return and bindM2 is equivalent to \ f ma mb ->
-- do {a <- ma; b <- mb; f a b} — the only difference is in
-- the resource utilisation. With the IO monad, on the other hand,
-- there may be visible difference in the results because the side
-- effects of ma and mb may be arbitrarily reordered.
module Control.Monad.Parallel
-- | Class of monads that can perform two computations in parallel and bind
-- their results together.
class Monad m => MonadParallel m
bindM2 :: MonadParallel m => (a -> b -> m c) -> m a -> m b -> m c
-- | Class of monads that can fork a parallel computation.
class MonadParallel m => MonadFork m
forkExec :: MonadFork m => m a -> m (m a)
-- | Perform three monadic computations in parallel; when they are all
-- finished, pass their results to the function.
bindM3 :: MonadParallel m => (a -> b -> c -> m d) -> m a -> m b -> m c -> m d
-- | Like Control.Monad.liftM2, but evaluating its two monadic
-- arguments in parallel.
liftM2 :: MonadParallel m => (a -> b -> c) -> m a -> m b -> m c
-- | Like Control.Monad.liftM3, but evaluating its three monadic
-- arguments in parallel.
liftM3 :: MonadParallel m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
-- | Like Control.Monad.ap, but evaluating the function and its
-- argument in parallel.
ap :: MonadParallel m => m (a -> b) -> m a -> m b
-- | Like Control.Monad.sequence, but executing the actions in
-- parallel.
sequence :: MonadParallel m => [m a] -> m [a]
-- | Like Control.Monad.sequence_, but executing the actions in
-- parallel.
sequence_ :: MonadParallel m => [m a] -> m ()
-- | Like Control.Monad.mapM, but applying the function to the
-- individual list items in parallel.
mapM :: MonadParallel m => (a -> m b) -> [a] -> m [b]
-- | Like Control.Monad.replicateM, but executing the action
-- multiple times in parallel.
replicateM :: MonadParallel m => Int -> m a -> m [a]
-- | Like Control.Monad.replicateM_, but executing the action
-- multiple times in parallel.
replicateM_ :: MonadParallel m => Int -> m a -> m ()
instance MonadFork m => MonadFork (ReaderT r m)
instance MonadFork m => MonadFork (ListT m)
instance (MonadFork m, Error e) => MonadFork (ErrorT e m)
instance MonadFork m => MonadFork (MaybeT m)
instance MonadFork m => MonadFork (IdentityT m)
instance MonadFork IO
instance MonadFork ((->) r)
instance MonadFork []
instance MonadFork Maybe
instance MonadParallel m => MonadParallel (ReaderT r m)
instance MonadParallel m => MonadParallel (ListT m)
instance (MonadParallel m, Error e) => MonadParallel (ErrorT e m)
instance MonadParallel m => MonadParallel (MaybeT m)
instance MonadParallel m => MonadParallel (IdentityT m)
instance MonadParallel IO
instance MonadParallel ((->) r)
instance MonadParallel []
instance MonadParallel Maybe
instance MonadParallel Identity