Later, during work on the shared-memory implementation of
parallelism in GHC, we discovered that the original formulation of
Strategies had some problems, in particular it lead to space leaks
and difficulties expressing speculative parallelism. Details are in
the paper "Runtime Support for Multicore Haskell" http://www.haskell.org/~simonmar/papers/multicore-ghc.pdf.

This module has been rewritten in version 2. The main change is to
the 'Strategy a' type synonym, which was previously a -> Done and
is now a -> Eval a. This change helps to fix the space leak described
in "Runtime Support for Multicore Haskell". The problem is that
the runtime will currently retain the memory referenced by all
sparks, until they are evaluated. Hence, we must arrange to
evaluate all the sparks eventually, just in case they aren't
evaluated in parallel, so that they don't cause a space leak. This
is why we must return a "new" value after applying a Strategy,
so that the application can evaluate each spark created by the
Strategy.

The simple rule is this: you must use the result of applying
a Strategy if the strategy creates parallel sparks, and you
should probably discard the the original value. If you don't
do this, currently it may result in a space leak. In the
future (GHC 6.14), it will probably result in lost parallelism
instead, as we plan to change GHC so that unreferenced sparks
are discarded rather than retained (we can't make this change
until most code is switched over to this new version of
Strategies, because code using the old verison of Strategies
would be broken by the change in policy).

Strategy type and basic operations

A Strategy is a function that embodies a parallel evaluation strategy.
The function traverses (parts of) its argument, evaluating subexpressions
in parallel or in sequence.

A Strategy may do an arbitrary amount of evaluation of its
argument, but should not return a value different from the one it
was passed.

Parallel computations may be discarded by the runtime system if the
program no longer requires their result, which is why a Strategy
function returns a new value equivalent to the old value. The
intention is that the program applies the Strategy to a
structure, and then uses the returned value, discarding the old
value. This idiom is expressed by the using function.

Applies a strategy to the nth element of list when the head is demanded.
More precisely:

semantics: parBuffer n s = id :: [a] -> [a]

dynamic behaviour: evalutates the nth element of the list when the
head is demanded.

The idea is to provide a `rolling buffer' of length n. It is a
better than parList for a lazy stream, because parList will
evaluate the entire list, whereas parBuffer will only evaluate a
fixed number of elements ahead.

Simple list strategies

version of parList specialised to rwhnf. This version is
much simpler, and may be faster than 'parList rwhnf'. You should
never need to use this directly, since 'parList rwhnf' is
automatically optimised to parListWHNF. It is here for
experimentation purposes only.

version of parBuffer specialised to rwhnf. You should
never need to use this directly, since 'parBuffer rwhnf' is
automatically optimised to parBufferWHNF. It is here for
experimentation purposes only.

Sequential inverse function composition,
for those who read their programs from left to right.
The result of the first function is evaluated using the
given strategy, and then given to the second function.

Parallel inverse function composition,
for those who read their programs from left to right.
The result of the first function is evaluated using the
given strategy, in parallel with the application of the
second function.

Building strategies

Eval is an Applicative Functor that makes it easier to define
parallel strategies that involve traversing structures.

a Seq value will be evaluated strictly in sequence in its context,
whereas a Par value wraps an expression that may be evaluated in
parallel. The Applicative instance allows sequential composition,
making it possible to describe an evaluateion strategy by composing
Par and Seq with <*>.