HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleabstract-par-0.3.3Haskell98

Control.Monad.Par.Class

This module establishes a class hierarchy that captures the interfaces of Par monads. There are two layers: simple futures (ParFuture) and full IVars (ParIVar). All Par monads are expected to implement the former, some also implement the latter.

For more documentation of the programming model, see

  • 3 classes

Futures

1 declaration
classclass Monad m => ParFuture (future :: Type -> Type) (m :: Type -> Type) | 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

    Wait for the result of a future, and then return it.

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

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

     spawnP = spawn . return

IVars

2 declarations
classclass ParFuture ivar m => ParIVar (ivar :: Type -> Type) (m :: Type -> Type) | 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)

classclass NFData a where
#

A class of types that can be fully evaluated.

Instances109NFData, …