Eval is the computation context used by Control.Parallel.Strategies to describe an evaluation plan. A Strategy has type a -> Eval a: it specifies which values should be evaluated in parallel and which should be forced sequentially, while leaving the program’s algorithm unchanged. section 13.4.2 section 13.5
Run an Eval computation with runEval to obtain its value. Within the computation, rpar creates a spark for parallel evaluation, while rseq evaluates a value sequentially. A spark does not make return wait: if its result is demanded too soon, the spark can fizzle; an already evaluated value produces a dud. section 13.4.3
Choose evaluation strategies according to how much of a value must be forced:
- r0 performs no evaluation. section 13.4.2
- rseq evaluates only to weak head normal form, reaching at least the first data constructor; list elements may remain unevaluated thunks. section 13.4.2
- rdeepseq forces a value completely to normal form. section 13.4.2
- rpar creates a spark that an available Haskell execution context may take from the spark pool and evaluate. section 13.4.2 section 13.4.3
Parallel list mapping
Apply evalList rpar with using or withStrategy to spark each element of a mapped list, as in map (^ 100) [1 .. 1000] `using` evalList rpar. For larger image vectors, avoid creating one spark per pixel: split the vector into larger chunks and evaluate those chunks in parallel, reducing spark-pool overflow. section 13.4.3 section 13.5
Figure 13.5 Haskell execution contexts and spark pools
The diagram shows how rpar fills a shared spark pool and how idle Haskell execution contexts use work stealing to pick up parallel work. section 13.4.3
Evaluation strategies provide parallelism rather than general concurrency. They are suited to the same pure computation being applied repeatedly, such as image processing over a collection. Runtime details handle cases where sparks are collected or evaluated before a worker reaches them, but spark counts still matter: too many sparks can make parallel execution ineffective. section 13.4.2 section 13.5
