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

Safe Haskell | Safe-Inferred
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 Source #

A class of types that can be fully evaluated.

Since: deepseq-1.1.0.0

#### Instances

Instances details

NFData ByteArray | Since: deepseq-1.4.7.0
Instance details Defined in Control.DeepSeq Methods rnf :: ByteArray -> () Source #
NFData All | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: All -> () Source #
NFData Any | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Any -> () Source #
NFData TypeRep | NOTE: Prior to `deepseq-1.4.4.0` this instance was only defined for `base-4.8.0.0` and later. Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: TypeRep -> () Source #
NFData Unique | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Unique -> () Source #
NFData Version | Since: deepseq-1.3.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Version -> () Source #
NFData Void | Defined as ``rnf` = `absurd``. Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Void -> () Source #
NFData CBool | Since: deepseq-1.4.3.0
Instance details Defined in Control.DeepSeq Methods rnf :: CBool -> () Source #
NFData CChar | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CChar -> () Source #
NFData CClock | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CClock -> () Source #
NFData CDouble | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CDouble -> () Source #
NFData CFile | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CFile -> () Source #
NFData CFloat | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CFloat -> () Source #
NFData CFpos | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CFpos -> () Source #
NFData CInt | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CInt -> () Source #
NFData CIntMax | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CIntMax -> () Source #
NFData CIntPtr | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CIntPtr -> () Source #
NFData CJmpBuf | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CJmpBuf -> () Source #
NFData CLLong | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CLLong -> () Source #
NFData CLong | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CLong -> () Source #
NFData CPtrdiff | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CPtrdiff -> () Source #
NFData CSChar | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CSChar -> () Source #
NFData CSUSeconds | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CSUSeconds -> () Source #
NFData CShort | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CShort -> () Source #
NFData CSigAtomic | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CSigAtomic -> () Source #
NFData CSize | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CSize -> () Source #
NFData CTime | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CTime -> () Source #
NFData CUChar | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CUChar -> () Source #
NFData CUInt | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CUInt -> () Source #
NFData CUIntMax | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CUIntMax -> () Source #
NFData CUIntPtr | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CUIntPtr -> () Source #
NFData CULLong | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CULLong -> () Source #
NFData CULong | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CULong -> () Source #
NFData CUSeconds | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CUSeconds -> () Source #
NFData CUShort | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CUShort -> () Source #
NFData CWchar | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: CWchar -> () Source #
NFData ThreadId | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: ThreadId -> () Source #
NFData Fingerprint | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Fingerprint -> () Source #
NFData MaskingState | Since: deepseq-1.4.4.0
Instance details Defined in Control.DeepSeq Methods rnf :: MaskingState -> () Source #
NFData ExitCode | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: ExitCode -> () Source #
NFData Int16 |
Instance details Defined in Control.DeepSeq Methods rnf :: Int16 -> () Source #
NFData Int32 |
Instance details Defined in Control.DeepSeq Methods rnf :: Int32 -> () Source #
NFData Int64 |
Instance details Defined in Control.DeepSeq Methods rnf :: Int64 -> () Source #
NFData Int8 |
Instance details Defined in Control.DeepSeq Methods rnf :: Int8 -> () Source #
NFData CallStack | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: CallStack -> () Source #
NFData SrcLoc | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: SrcLoc -> () Source #
NFData Word16 |
Instance details Defined in Control.DeepSeq Methods rnf :: Word16 -> () Source #
NFData Word32 |
Instance details Defined in Control.DeepSeq Methods rnf :: Word32 -> () Source #
NFData Word64 |
Instance details Defined in Control.DeepSeq Methods rnf :: Word64 -> () Source #
NFData Word8 |
Instance details Defined in Control.DeepSeq Methods rnf :: Word8 -> () Source #
NFData Ordering |
Instance details Defined in Control.DeepSeq Methods rnf :: Ordering -> () Source #
NFData TyCon | NOTE: Prior to `deepseq-1.4.4.0` this instance was only defined for `base-4.8.0.0` and later. Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: TyCon -> () Source #
NFData Integer |
Instance details Defined in Control.DeepSeq Methods rnf :: Integer -> () Source #
NFData Natural | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Natural -> () Source #
NFData () |
Instance details Defined in Control.DeepSeq Methods rnf :: () -> () Source #
NFData Bool |
Instance details Defined in Control.DeepSeq Methods rnf :: Bool -> () Source #
NFData Char |
Instance details Defined in Control.DeepSeq Methods rnf :: Char -> () Source #
NFData Double |
Instance details Defined in Control.DeepSeq Methods rnf :: Double -> () Source #
NFData Float |
Instance details Defined in Control.DeepSeq Methods rnf :: Float -> () Source #
NFData Int |
Instance details Defined in Control.DeepSeq Methods rnf :: Int -> () Source #
NFData Word |
Instance details Defined in Control.DeepSeq Methods rnf :: Word -> () Source #
NFData a => NFData (ZipList a) | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: ZipList a -> () Source #
NFData (MutableByteArray s) | Since: deepseq-1.4.8.0
Instance details Defined in Control.DeepSeq Methods rnf :: MutableByteArray s -> () Source #
NFData a => NFData (Complex a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Complex a -> () Source #
NFData a => NFData (Identity a) | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Identity a -> () Source #
NFData a => NFData (First a) | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: First a -> () Source #
NFData a => NFData (Last a) | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Last a -> () Source #
NFData a => NFData (Down a) | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Down a -> () Source #
NFData a => NFData (First a) | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: First a -> () Source #
NFData a => NFData (Last a) | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: Last a -> () Source #
NFData a => NFData (Max a) | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: Max a -> () Source #
NFData a => NFData (Min a) | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: Min a -> () Source #
NFData m => NFData (WrappedMonoid m) | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: WrappedMonoid m -> () Source #
NFData a => NFData (Dual a) | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Dual a -> () Source #
NFData a => NFData (Product a) | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Product a -> () Source #
NFData a => NFData (Sum a) | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Sum a -> () Source #
NFData (IORef a) | NOTE: Only strict in the reference and not the referenced value. Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: IORef a -> () Source #
NFData (MVar a) | NOTE: Only strict in the reference and not the referenced value. Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: MVar a -> () Source #
NFData (FunPtr a) | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: FunPtr a -> () Source #
NFData (Ptr a) | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: Ptr a -> () Source #
NFData a => NFData (Ratio a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Ratio a -> () Source #
NFData (StableName a) | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: StableName a -> () Source #
NFData a => NFData (NonEmpty a) | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: NonEmpty a -> () Source #
NFData a => NFData (Maybe a) |
Instance details Defined in Control.DeepSeq Methods rnf :: Maybe a -> () Source #
NFData a => NFData (a) | Since: deepseq-1.4.6.0
Instance details Defined in Control.DeepSeq Methods rnf :: (a) -> () Source #
NFData a => NFData [a] |
Instance details Defined in Control.DeepSeq Methods rnf :: [a] -> () Source #
(NFData a, NFData b) => NFData (Either a b) |
Instance details Defined in Control.DeepSeq Methods rnf :: Either a b -> () Source #
NFData (Fixed a) | Since: deepseq-1.3.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Fixed a -> () Source #
NFData (Proxy a) | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Proxy a -> () Source #
(NFData a, NFData b) => NFData (Arg a b) | Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: Arg a b -> () Source #
(NFData a, NFData b) => NFData (Array a b) |
Instance details Defined in Control.DeepSeq Methods rnf :: Array a b -> () Source #
NFData (STRef s a) | NOTE: Only strict in the reference and not the referenced value. Since: deepseq-1.4.2.0
Instance details Defined in Control.DeepSeq Methods rnf :: STRef s a -> () Source #
NFData (a -> b) | This instance is for convenience and consistency with `seq`. This assumes that WHNF is equivalent to NF for functions. Since: deepseq-1.3.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: (a -> b) -> () Source #
(NFData a, NFData b) => NFData (a, b) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a, b) -> () Source #
NFData a => NFData (Const a b) | Since: deepseq-1.4.0.0
Instance details Defined in Control.DeepSeq Methods rnf :: Const a b -> () Source #
NFData (a :~: b) | Since: deepseq-1.4.3.0
Instance details Defined in Control.DeepSeq Methods rnf :: (a :~: b) -> () Source #
(NFData a1, NFData a2, NFData a3) => NFData (a1, a2, a3) |
Instance details Defined in Control.DeepSeq Methods rnf :: (a1, a2, a3) -> () Source #
(NFData1 f, NFData1 g, NFData a) => NFData (Product f g a) | Since: deepseq-1.4.3.0
Instance details Defined in Control.DeepSeq Methods rnf :: Product f g a -> () Source #
(NFData1 f, NFData1 g, NFData a) => NFData (Sum f g a) | Since: deepseq-1.4.3.0
Instance details Defined in Control.DeepSeq Methods rnf :: Sum f g a -> () Source #
NFData (a :~~: b) | Since: deepseq-1.4.3.0
Instance details Defined in Control.DeepSeq Methods rnf :: (a :~~: b) -> () Source #
(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) -> () Source #
(NFData1 f, NFData1 g, NFData a) => NFData (Compose f g a) | Since: deepseq-1.4.3.0
Instance details Defined in Control.DeepSeq Methods rnf :: Compose f g a -> () Source #
(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) -> () Source #
(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) -> () Source #
(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) -> () Source #
(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) -> () Source #
(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) -> () Source #