meta-par-0.3: Provides the monad-par interface, but based on modular scheduler "mix-ins".

Safe HaskellTrustworthy

Control.Monad.Par.Meta.Serial

Contents

Synopsis

Meta-Par monad for single-threaded execution

data Par a Source

The Meta-Par monad specialized for single-threaded execution.

Operations

class Monad m => ParFuture future m | m -> future where

ParFuture captures the class of Par monads which support futures. This level of functionality subsumes par/pseq and is similar to the Control.Parallel.Strategies.Eval monad.

A minimal implementation consists of spawn_ and get. However, for monads that are also a member of ParIVar it is typical to simply define spawn in terms of fork, new, and put.

Methods

spawn :: NFData a => m a -> m (future a)

Create a potentially-parallel computation, and return a future (or promise) that can be used to query the result of the forked computataion.

  spawn p = do
    r <- new
    fork (p >>= put r)
    return r

spawn_ :: m a -> m (future a)

Like spawn, but the result is only head-strict, not fully-strict.

get :: future a -> m a

spawnP :: NFData a => a -> m (future a)

Spawn a pure (rather than monadic) computation. Fully-strict.

  spawnP = spawn . return

class ParFuture ivar m => ParIVar ivar m | m -> ivar where

ParIVar builds on futures by adding full anyone-writes, anyone-reads IVars. These are more expressive but may not be supported by all distributed schedulers.

A minimal implementation consists of fork, put_, and new.

Methods

fork :: m () -> m ()

Forks a computation to happen in parallel. The forked computation may exchange values with other computations using IVars.

new :: m (ivar a)

creates a new IVar

put :: NFData a => ivar a -> a -> m ()

put a value into a IVar. Multiple puts to the same IVar are not allowed, and result in a runtime error.

put fully evaluates its argument, which therefore must be an instance of NFData. The idea is that this forces the work to happen when we expect it, rather than being passed to the consumer of the IVar and performed later, which often results in less parallelism than expected.

Sometimes partial strictness is more appropriate: see put_.

put_ :: ivar a -> a -> m ()

like put, but only head-strict rather than fully-strict.

newFull :: NFData a => a -> m (ivar a)

creates a new IVar that contains a value

newFull_ :: a -> m (ivar a)

creates a new IVar that contains a value (head-strict only)

Entrypoints

runPar :: Par a -> aSource