Changes between Version 2 and Version 3 of monadparallel
 Timestamp:
 03/20/10 20:04:14 (8 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

monadparallel
v2 v3 1 1 = monadparallel = 2 2 3 The package ''monadparallel'' defines classes of monads that are capable of: 3 The lowlevel libraries available with GHC provide two completely different ways to execute tasks in parallel: [http://hackage.haskell.org/packages/archive/parallel/1.1.0.1/doc/html/ControlParallel.html#v:par par] and [http://www.haskell.org/ghc/docs/latest/html/libraries/base4.2.0.0/ControlConcurrent.html#v%3AforkIO forkIO]. The former can be applied to any pure computation, while the latter works only in the IO monad. 4 5 The purpose of the ''monadparallel'' library package is to unify the two approaches. For this purpose, it defines classes of monads that are capable of: 4 6 * splitting or forking monadic computations to be performed in parallel, and 5 7 * combining the results of those computations when they complete. 8 9 The way these classes are implemented by the IO monad (as well as any MonadIO instance) is different from the way they're implemented by stateless monads, but the classes abstract these implementation details away. 10 11 == Class `MonadFork` == 12 13 A monad that's an instance of the `MonadFork` class supports method 14 15 {{{ 16 forkExec :: MonadFork m => m a > m (m a) 17 }}} 18 19 This function launches the argument computation in a parallel thread and returns a handle to it. The main thread is free to perform some other task and then obtain the result of the parallel computation: 20 21 {{{ 22 task1 :: Monad Int 23 task2 :: Monad Int 24 task3 :: Monad Int 25 26 example = do handle1 < forkExec task1 27 handle2 < forkExec task2 28 result3 < task3 29 result1 < handle1 30 result2 < handle2 31 return (result1 + result2 + result3) 32 }}} 33 34 == Class `MonadParallel` == 35 36 A monad that's an instance of the `MonadParallel` class supports method 37 38 {{{ 39 bindM2 :: MonadParallel m => (a > b > m c) > m a > m b > m c 40 }}} 41