-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Concurrent utilities -- -- Concurrent utilities @package ConcurrentUtils @version 0.3.0.0 -- | A module of concurrent higher order functions. module Control.CUtils.Conc -- | For exceptions caused by caller code. data ExceptionList ExceptionList :: [SomeException] -> ExceptionList -- | For internal errors. If a procedure throws this, some threads it -- created may still be running. It is thrown separately from -- ExceptionList. data ConcException ConcException :: ConcException -- | Runs an associative folding function on the given list. Note: this -- function only spawns enough threads to make effective use of the -- capabilities. Any two list elements may be processed -- sequentially or concurrently. To get parallelism, you have to set the -- numCapabilities value, e.g. using GHC's +RTS -N flag. assocFold :: (a -> a -> IO a) -> Array Int a -> IO a concF_ :: ?seq :: Bool => Int -> (Int -> IO ()) -> IO () conc_ :: (?seq :: Bool) -> Array Int (IO ()) -> IO () -- | The next three functions take an implicit parameter ?seq. Set it to -- True if you want to only spawn threads for the capabilities (same as -- assocFold, good for speed). if you need all the actions to be -- executed concurrently, set it to False. -- -- These functions promise O(m f(n)/c) time, provided: -- -- -- -- n is the number of computations which are indexed from 0 to n - 1. concF :: ?seq :: Bool => Int -> (Int -> IO e) -> IO (Array Int e) -- | Runs several computations concurrently, and returns their results as -- an array. Waits for all threads to end before returning. conc :: ?seq :: Bool => Array Int (IO e) -> IO (Array Int e) -- | Version of concF specialized for two computations. concP :: ?seq :: Bool => IO t -> IO t1 -> IO (t, t1) oneOfF :: Int -> (Int -> IO a) -> IO a -- | Runs several computations in parallel, and returns one of their -- results (terminating the other computations). oneOf :: Array Int (IO a) -> IO a instance Typeable ExceptionList instance Typeable ConcException instance Show ExceptionList instance Show ConcException instance Exception ConcException instance Exception ExceptionList -- | An implementation of nested data parallelism module Control.CUtils.DataParallel data ArrC t inject :: Array Int e -> ArrC e project :: ArrC t -> Array Int t newArray :: [e] -> Array Int e -- | Constructors for caller's use data A t u Count :: A Int (ArrC Int) Index :: A (ArrC t, Int) t Zip :: A (ArrC t, ArrC u) (ArrC (t, u)) Unzip :: A (ArrC (t, u)) (ArrC t, ArrC u) Concat :: A (ArrC (ArrC t)) (ArrC t) Map :: A t u -> A (ArrC t) (ArrC u) Comp :: A u v -> A t u -> A t v Arr :: (t -> u) -> A t u Prod :: A t u -> A v w -> A (t, v) (u, w) Sum :: A t u -> A v w -> A (Either t v) (Either u w) -- | Optimizes an arrow for parallel execution. The arrow can be optimized -- once, and the result saved for multiple computations. (The exact -- output of the optimizer is subject to change.) -- -- The arrow must be finitely examinable. optimize :: A a v -> A a v -- | Evaluates arrows. eval :: A t u -> t -> u instance Show (A t u) instance ArrowChoice A instance Arrow A instance Category A instance Show (t -> u) instance Functor ArrC -- | Automatic deadlock prevention. -- -- Automatic deadlock detection is inefficient, and computations cannot -- be rolled back or aborted in general. -- -- Instead, we prevent deadlocks before they happen. module Control.CUtils.Deadlock -- | The Res arrow. data Res t u Lift :: Kleisli IO t v -> Res v u -> Res t u Acq :: MVar () -> Res t u -> Res t u Rel :: MVar () -> Res t u -> Res t u Fork :: Res t () -> Res t u -> Res t u Plus :: Res t v -> Res u v -> Res (Either t u) v Id :: Res t t -- | Use this to run computations built in the Res arrow. Pieces of the -- arrow that hold locks must be finitely examinable, otherwise it -- doesn't terminate. run :: Res t u -> t -> IO u lft :: IO a -> Res v u -> Res v u instance ArrowChoice Res instance Arrow Res instance Category Res -- | Lists suitable for parallel execution (taken from Hackage's monad-par -- package). (For converting to regular lists, there is the toList -- function in Data.Foldable.) module Control.CUtils.AList data AList t Append :: (AList t) -> (AList t) -> AList t List :: [t] -> AList t -- | Filters the AList using a predicate. filterAList :: (b -> Bool) -> AList b -> AList b -- | Folds the AList with a function, that must be associative. This allows -- parallelism to be introduced. assocFold :: (c -> c -> c) -> AList c -> c -- | Combine monoid elements to get a result. monoid :: (Monoid a, Eq a) => AList a -> a -- | Length of an AList. lenAList :: (Num a, Eq a1) => AList a1 -> a -- | Find the first element satisfying a predicate. findAList :: Eq a => (a -> Bool) -> AList a -> Maybe a -- | Concatenate an AList of ALists. concatAList :: Monad m => m (m b) -> m b instance Eq t => Eq (AList t) instance Ord t => Ord (AList t) instance Show t => Show (AList t) instance Foldable AList instance Traversable AList instance Functor AList instance MonadPlus AList instance Monad AList -- | Functional channels | A channel data type which allows consumers to -- hold references to different points in a stream at the same time. -- Elements of a channel are kept alive only so long as there are -- references pointing before those elements. And producers on a channel -- are kept alive only so long as there are consumers. module Control.CUtils.FChan data Chan t -- | Thrown by the writer function when the garbage collector detects that -- no one will read it. data DoneReadingException DoneReadingException :: DoneReadingException -- | Take the first element from a channel, and a channel representing the -- remainder of the output. takeChan :: Chan t -> IO (t, Chan t) -- | Create a new channel. The first return value is a function that can be -- used to add values to the channel. The second return value is the -- channel itself. newChan :: IO (t -> IO (), Chan t) -- | The first return value is a thunk that returns values from the channel -- successively, starting from the position of the parameter channel. The -- second thunk can be used to retrieve the position of the channel after -- all the reads made using the first thunk. makeConsumer :: Chan b -> IO (IO b, IO (Chan b)) instance Typeable DoneReadingException instance Show DoneReadingException instance Exception DoneReadingException -- | An implementation of communicating sequential processes. module Control.CUtils.Processes -- | The CSP data type: -- -- :|| - interleave -- -- :? - deterministic choice -- -- Join - interface parallel -- -- :-> - prefix -- -- Stop - empty computation -- -- Do - execute IO, then behave as the returned process data CSP (:||) :: CSP -> CSP -> CSP (:?) :: CSP -> CSP -> CSP Join :: CSP -> [String] -> CSP -> CSP (:->) :: String -> CSP -> CSP Stop :: CSP Do :: (IO CSP) -> CSP runCSP0 :: (String -> IO (), Chan String) -> [(MVar Side, String, Side)] -> CSP -> IO () -- | Run a CSP computation. runCSP :: CSP -> IO () instance Show CSP instance Eq Side instance Show (IO t)