parfold-0.9: Parallel folds

Portabilityunportable
Stabilitystable
MaintainerMartin Avanzini <martin.avanzini@uibk.ac.at>
Safe HaskellSafe-Infered

Control.Concurrent.PFold

Contents

Description

This module provides implements parallel folding of associative operators, and some convenience utilities implemented on top of it.

Synopsis

Documentation

pfold :: (a -> b -> a) -> a -> [IO b] -> IO a

The call 'pfold f a ms' executes the io actions ms in parallel, and collects the results of using the function f and the initial value a. No guarantee on the order of the folding is given, and thus f should be associative.

If an io action from ms receives an uncought exception, then the specific io action is silently ignored.

pfoldA :: (a -> b -> Return a) -> a -> [IO b] -> IO a

Same as pfold but allows the folding operator to abort the computation and return a result immediately. All pending spawned io actions are cilled.

data Return a

Constructors

Stop a

Stop computation of other subprocesses

Continue a

Usual return behaviour

The result type of the folding function for the pfoldA.

Utilities Implemented on top of pfold

The following actions are all implemented on top of pfoldA, hence again actions that receive an uncaught exception are silently ignored

fastest :: a -> [IO a] -> IO a

The call 'fastest a ms' executes the io actions ms in parallel, and returns the first computed result, or a if the io actions ms are empty.

fastestSatisfying :: (a -> Bool) -> a -> [IO a] -> IO a

Same as fastest, but additionally checks a predicate on the returned result. If the predicate does not hold, the result is discarded.

alt :: IO a -> [IO a] -> IO a

The call 'alt m ms' executes all actions in 'm:ms' in parallel, and returns the fastest computed result.

choice :: IO a -> IO a -> IO a

'choice a b == alt a [b]'

par :: IO a -> IO b -> IO (a, b)

'par ma mb' runs the action ma and mb in parallel, returning their result. The actions ma and mb need to properly catch all exceptions, or otherwise the call might hang indefinately

(<+>) :: forall a b. IO a -> IO b -> IO (a, b)

Infix version of par.

(<|>) :: forall a. IO a -> IO a -> IO a

Infix version of choice.