abstract-par-0.3.3: Type classes generalizing the functionality of the 'monad-par' library.

Safe Haskell | Safe
Language | Haskell98

Control.Monad.Par.Class

Contents

- Futures
- IVars

Description

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

- The Control.Monad.Par module in the `monad-par` package.
- The wiki/tutorial (http://www.haskell.org/haskellwiki/Par_Monad:_A_Parallelism_Tutorial)
- The original paper (http://www.cs.indiana.edu/~rrnewton/papers/haskell2011_monad-par.pdf)
- Tutorial slides (http://community.haskell.org/~simonmar/slides/CUFP.pdf)
- Other slides (http://www.cs.ox.ac.uk/ralf.hinze/WG2.8/28/slides/simon.pdf, http://www.cs.indiana.edu/~rrnewton/talks/2011_HaskellSymposium_ParMonad.pdf)

Synopsis

- class Monad m => ParFuture future m | m -> future where
  - spawn :: NFData a => m a -> m (future a)
  - spawn_ :: m a -> m (future a)
  - get :: future a -> m a
  - spawnP :: NFData a => a -> m (future a)
- class ParFuture ivar m => ParIVar ivar m | m -> ivar where
  - fork :: m () -> m ()
  - new :: m (ivar a)
  - put :: NFData a => ivar a -> a -> m ()
  - put_ :: ivar a -> a -> m ()
  - newFull :: NFData a => a -> m (ivar a)
  - newFull_ :: a -> m (ivar a)
- class NFData a

# Futures

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

`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`.

Minimal complete definition

spawn_, get

Methods

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

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) Source #

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

get :: future a -> m a Source #

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

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

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

     spawnP = spawn . return

# IVars

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

`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`.

Minimal complete definition

fork, new, put_

Methods

fork :: m () -> m () Source #

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

new :: m (ivar a) Source #

creates a new `IVar`

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

put a value into a `IVar`. Multiple `put`s 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 () Source #

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

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

creates a new `IVar` that contains a value

newFull_ :: a -> m (ivar a) Source #

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

class NFData a #

#### Instances

Instances details

NFData Bool |
Instance details Defined in Control.DeepSeq Methods rnf :: Bool -> ()
NFData Char |
Instance details Defined in Control.DeepSeq Methods rnf :: Char -> ()
NFData Double |
Instance details Defined in Control.DeepSeq Methods rnf :: Double -> ()
NFData Float |
Instance details Defined in Control.DeepSeq Methods rnf :: Float -> ()
NFData Int |
Instance details Defined in Control.DeepSeq Methods rnf :: Int -> ()
NFData Int8 |
Instance details Defined in Control.DeepSeq Methods rnf :: Int8 -> ()
NFData Int16 |
Instance details Defined in Control.DeepSeq Methods rnf :: Int16 -> ()
NFData Int32 |
Instance details Defined in Control.DeepSeq Methods rnf :: Int32 -> ()
NFData Int64 |
Instance details Defined in Control.DeepSeq Methods rnf :: Int64 -> ()
NFData Integer |
Instance details Defined in Control.DeepSeq Methods rnf :: Integer -> ()
NFData Natural |
Instance details Defined in Control.DeepSeq Methods rnf :: Natural -> ()
NFData Ordering |
Instance details Defined in Control.DeepSeq Methods rnf :: Ordering -> ()
NFData Word |
Instance details Defined in Control.DeepSeq Methods rnf :: Word -> ()
NFData Word8 |
Instance details Defined in Control.DeepSeq Methods rnf :: Word8 -> ()
NFData Word16 |
Instance details Defined in Control.DeepSeq Methods rnf :: Word16 -> ()
NFData Word32 |
Instance details Defined in Control.DeepSeq Methods rnf :: Word32 -> ()
NFData Word64 |
Instance details Defined in Control.DeepSeq Methods rnf :: Word64 -> ()
NFData CallStack |
Instance details Defined in Control.DeepSeq Methods rnf :: CallStack -> ()
NFData () |
Instance details Defined in Control.DeepSeq Methods rnf :: () -> ()
NFData TyCon |
Instance details Defined in Control.DeepSeq Methods rnf :: TyCon -> ()
NFData All |
Instance details Defined in Control.DeepSeq Methods rnf :: All -> ()
NFData Any |
Instance details Defined in Control.DeepSeq Methods rnf :: Any -> ()
NFData CBool |
Instance details Defined in Control.DeepSeq Methods rnf :: CBool -> ()
NFData CChar |
Instance details Defined in Control.DeepSeq Methods rnf :: CChar -> ()
NFData CClock |
Instance details Defined in Control.DeepSeq Methods rnf :: CClock -> ()
NFData CDouble |
Instance details Defined in Control.DeepSeq Methods rnf :: CDouble -> ()
NFData CFile |
Instance details Defined in Control.DeepSeq Methods rnf :: CFile -> ()
NFData CFloat |
Instance details Defined in Control.DeepSeq Methods rnf :: CFloat -> ()
NFData CFpos |
Instance details Defined in Control.DeepSeq Methods rnf :: CFpos -> ()
NFData CInt |
Instance details Defined in Control.DeepSeq Methods rnf :: CInt -> ()
NFData CIntMax |
Instance details Defined in Control.DeepSeq Methods rnf :: CIntMax -> ()
NFData CIntPtr |
Instance details Defined in Control.DeepSeq Methods rnf :: CIntPtr -> ()
NFData CJmpBuf |
Instance details Defined in Control.DeepSeq Methods rnf :: CJmpBuf -> ()
NFData CLLong |
Instance details Defined in Control.DeepSeq Methods rnf :: CLLong -> ()
NFData CLong |
Instance details Defined in Control.DeepSeq Methods rnf :: CLong -> ()
NFData CPtrdiff |
Instance details Defined in Control.DeepSeq Methods rnf :: CPtrdiff -> ()
NFData CSChar |
Instance details Defined in Control.DeepSeq Methods rnf :: CSChar -> ()
NFData CSUSeconds |
Instance details Defined in Control.DeepSeq Methods rnf :: CSUSeconds -> ()
NFData CShort |
Instance details Defined in Control.DeepSeq Methods rnf :: CShort -> ()
NFData CSigAtomic |
Instance details Defined in Control.DeepSeq Methods rnf :: CSigAtomic -> ()
NFData CSize |
Instance details Defined in Control.DeepSeq Methods rnf :: CSize -> ()
NFData CTime |
Instance details Defined in Control.DeepSeq Methods rnf :: CTime -> ()
NFData CUChar |
Instance details Defined in Control.DeepSeq Methods rnf :: CUChar -> ()
NFData CUInt |
Instance details Defined in Control.DeepSeq Methods rnf :: CUInt -> ()
NFData CUIntMax |
Instance details Defined in Control.DeepSeq Methods rnf :: CUIntMax -> ()
NFData CUIntPtr |
Instance details Defined in Control.DeepSeq Methods rnf :: CUIntPtr -> ()
NFData CULLong |
Instance details Defined in Control.DeepSeq Methods rnf :: CULLong -> ()
NFData CULong |
Instance details Defined in Control.DeepSeq Methods rnf :: CULong -> ()
NFData CUSeconds |
Instance details Defined in Control.DeepSeq Methods rnf :: CUSeconds -> ()
NFData CUShort |
Instance details Defined in Control.DeepSeq Methods rnf :: CUShort -> ()
NFData CWchar |
Instance details Defined in Control.DeepSeq Methods rnf :: CWchar -> ()
NFData ExitCode |
Instance details Defined in Control.DeepSeq Methods rnf :: ExitCode -> ()
NFData Fingerprint |
Instance details Defined in Control.DeepSeq Methods rnf :: Fingerprint -> ()
NFData MaskingState |
Instance details Defined in Control.DeepSeq Methods rnf :: MaskingState -> ()
NFData TypeRep |
Instance details Defined in Control.DeepSeq Methods rnf :: TypeRep -> ()
NFData SrcLoc |
Instance details Defined in Control.DeepSeq Methods rnf :: SrcLoc -> ()
NFData ThreadId |
Instance details Defined in Control.DeepSeq Methods rnf :: ThreadId -> ()
NFData Unique |
Instance details Defined in Control.DeepSeq Methods rnf :: Unique -> ()
NFData Version |
Instance details Defined in Control.DeepSeq Methods rnf :: Version -> ()
NFData Void |
Instance details Defined in Control.DeepSeq Methods rnf :: Void -> ()
NFData a => NFData [a] |
Instance details Defined in Control.DeepSeq Methods rnf :: [a] -> ()
NFData a => NFData (Maybe a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Maybe a -> ()
NFData a => NFData (Ratio a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Ratio a -> ()
NFData (Ptr a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Ptr a -> ()
NFData (FunPtr a) |
Instance details Defined in Control.DeepSeq Methods rnf :: FunPtr a -> ()
NFData a => NFData (Down a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Down a -> ()
NFData a => NFData (Dual a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Dual a -> ()
NFData a => NFData (First a) |
Instance details Defined in Control.DeepSeq Methods rnf :: First a -> ()
NFData a => NFData (First a) |
Instance details Defined in Control.DeepSeq Methods rnf :: First a -> ()
NFData (Fixed a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Fixed a -> ()
NFData (IORef a) |
Instance details Defined in Control.DeepSeq Methods rnf :: IORef a -> ()
NFData a => NFData (Identity a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Identity a -> ()
NFData a => NFData (Last a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Last a -> ()
NFData a => NFData (Last a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Last a -> ()
NFData (MVar a) |
Instance details Defined in Control.DeepSeq Methods rnf :: MVar a -> ()
NFData a => NFData (Max a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Max a -> ()
NFData a => NFData (Min a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Min a -> ()
NFData a => NFData (NonEmpty a) |
Instance details Defined in Control.DeepSeq Methods rnf :: NonEmpty a -> ()
NFData a => NFData (Option a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Option a -> ()
NFData a => NFData (Product a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Product a -> ()
NFData (StableName a) |
Instance details Defined in Control.DeepSeq Methods rnf :: StableName a -> ()
NFData a => NFData (Sum a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Sum a -> ()
NFData m => NFData (WrappedMonoid m) |
Instance details Defined in Control.DeepSeq Methods rnf :: WrappedMonoid m -> ()
NFData a => NFData (ZipList a) |
Instance details Defined in Control.DeepSeq Methods rnf :: ZipList a -> ()
NFData a => NFData (Complex a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Complex a -> ()
NFData (a -> b) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a -> b) -> ()
(NFData a, NFData b) => NFData (Either a b) |
Instance details Defined in Control.DeepSeq Methods rnf :: Either a b -> ()
(NFData a, NFData b) => NFData (a, b) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a, b) -> ()
(NFData a, NFData b) => NFData (Arg a b) |
Instance details Defined in Control.DeepSeq Methods rnf :: Arg a b -> ()
(NFData a, NFData b) => NFData (Array a b) |
Instance details Defined in Control.DeepSeq Methods rnf :: Array a b -> ()
NFData (Proxy a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Proxy a -> ()
NFData (STRef s a) |
Instance details Defined in Control.DeepSeq Methods rnf :: STRef s a -> ()
(NFData a1, NFData a2, NFData a3) => NFData (a1, a2, a3) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a1, a2, a3) -> ()
NFData (a :~: b) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a :~: b) -> ()
NFData a => NFData (Const a b) |
Instance details Defined in Control.DeepSeq Methods rnf :: Const a b -> ()
(NFData a1, NFData a2, NFData a3, NFData a4) => NFData (a1, a2, a3, a4) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a1, a2, a3, a4) -> ()
NFData (a :~~: b) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a :~~: b) -> ()
(NFData1 f, NFData1 g, NFData a) => NFData (Product f g a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Product f g a -> ()
(NFData1 f, NFData1 g, NFData a) => NFData (Sum f g a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Sum f g a -> ()
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5) => NFData (a1, a2, a3, a4, a5) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a1, a2, a3, a4, a5) -> ()
(NFData1 f, NFData1 g, NFData a) => NFData (Compose f g a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Compose f g a -> ()
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6) => NFData (a1, a2, a3, a4, a5, a6) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a1, a2, a3, a4, a5, a6) -> ()
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7) => NFData (a1, a2, a3, a4, a5, a6, a7) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a1, a2, a3, a4, a5, a6, a7) -> ()
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8) => NFData (a1, a2, a3, a4, a5, a6, a7, a8) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a1, a2, a3, a4, a5, a6, a7, a8) -> ()
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8, NFData a9) => NFData (a1, a2, a3, a4, a5, a6, a7, a8, a9) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a1, a2, a3, a4, a5, a6, a7, a8, a9) -> ()