Control.Seq

parallel-3.2.1.0: Parallel programming library

Copyright | (c) The University of Glasgow 2001-2009
License | BSD-style (see the file libraries/base/LICENSE)
Maintainer | libraries@haskell.org
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell2010

Control.Seq

Contents

- The sequential strategy type
- Application of sequential strategies
- Basic sequential strategies
- Sequential strategies for lists
- Sequential strategies for foldable data types
- Sequential strategies for tuples

Description

Sequential strategies provide ways to compositionally specify the degree of evaluation of a data type between the extremes of no evaluation and full evaluation. Sequential strategies may be viewed as complimentary to the parallel ones (see module Control.Parallel.Strategies).

Synopsis

- type Strategy a = a -> ()
- using :: a -> Strategy a -> a
- withStrategy :: Strategy a -> a -> a
- r0 :: Strategy a
- rseq :: Strategy a
- rdeepseq :: NFData a => Strategy a
- seqList :: Strategy a -> Strategy [a]
- seqListN :: Int -> Strategy a -> Strategy [a]
- seqListNth :: Int -> Strategy a -> Strategy [a]
- seqFoldable :: Foldable t => Strategy a -> Strategy (t a)
- seqMap :: Strategy k -> Strategy v -> Strategy (Map k v)
- seqArray :: Ix i => Strategy a -> Strategy (Array i a)
- seqArrayBounds :: Ix i => Strategy i -> Strategy (Array i a)
- seqTuple2 :: Strategy a -> Strategy b -> Strategy (a, b)
- seqTuple3 :: Strategy a -> Strategy b -> Strategy c -> Strategy (a, b, c)
- seqTuple4 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy (a, b, c, d)
- seqTuple5 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy (a, b, c, d, e)
- seqTuple6 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy (a, b, c, d, e, f)
- seqTuple7 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy g -> Strategy (a, b, c, d, e, f, g)
- seqTuple8 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy g -> Strategy h -> Strategy (a, b, c, d, e, f, g, h)
- seqTuple9 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy g -> Strategy h -> Strategy i -> Strategy (a, b, c, d, e, f, g, h, i)

# The sequential strategy type

type Strategy a = a -> ()

The type ``Strategy` a` is `a -> ()`. Thus, a strategy is a function whose sole purpose it is to evaluate its argument (either in full or in part).

# Application of sequential strategies

using :: a -> Strategy a -> a infixl 0

Evaluate a value using the given strategy.

withStrategy :: Strategy a -> a -> a

Evaluate a value using the given strategy. This is simply `using` with arguments reversed.

# Basic sequential strategies

r0 :: Strategy a

`r0` performs *no* evaluation.

rseq :: Strategy a

`rseq` evaluates its argument to weak head normal form.

rdeepseq :: NFData a => Strategy a

`rdeepseq` fully evaluates its argument. Relies on class `NFData` from module Control.DeepSeq.

# Sequential strategies for lists

seqList :: Strategy a -> Strategy [a]

Evaluate each element of a list according to the given strategy. This function is a specialisation of `seqFoldable` to lists.

seqListN :: Int -> Strategy a -> Strategy [a]

Evaluate the first n elements of a list according to the given strategy.

seqListNth :: Int -> Strategy a -> Strategy [a]

Evaluate the nth element of a list (if there is such) according to the given strategy. The spine of the list up to the nth element is evaluated as a side effect.

# Sequential strategies for foldable data types

seqFoldable :: Foldable t => Strategy a -> Strategy (t a)

Evaluate the elements of a foldable data structure according to the given strategy.

seqMap :: Strategy k -> Strategy v -> Strategy (Map k v)

Evaluate the keys and values of a map according to the given strategies.

seqArray :: Ix i => Strategy a -> Strategy (Array i a)

Evaluate the elements of an array according to the given strategy. Evaluation of the array bounds may be triggered as a side effect.

seqArrayBounds :: Ix i => Strategy i -> Strategy (Array i a)

Evaluate the bounds of an array according to the given strategy.

# Sequential strategies for tuples

Evaluate the components of a tuple according to the given strategies. No guarantee is given as to the order of evaluation.

seqTuple2 :: Strategy a -> Strategy b -> Strategy (a, b)

seqTuple3 :: Strategy a -> Strategy b -> Strategy c -> Strategy (a, b, c)

seqTuple4 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy (a, b, c, d)

seqTuple5 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy (a, b, c, d, e)

seqTuple6 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy (a, b, c, d, e, f)

seqTuple7 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy g -> Strategy (a, b, c, d, e, f, g)

seqTuple8 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy g -> Strategy h -> Strategy (a, b, c, d, e, f, g, h)

seqTuple9 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy g -> Strategy h -> Strategy i -> Strategy (a, b, c, d, e, f, g, h, i)