Haskell LanguageParallelism


Parameters

Type/FunctionDetail
data Eval aEval is a Monad that makes it easier to define parallel strategies
type Strategy a = a -> Eval aa function that embodies a parallel evaluation strategy. The function traverses (parts of) its argument, evaluating subexpressions in parallel or in sequence
rpar :: Strategy asparks its argument (for evaluation in parallel)
rseq :: Strategy aevaluates its argument to weak head normal form
force :: NFData a => a -> aevaluates the entire structure of its argument, reducing it to normal form, before returning the argument itself. It is provided by the Control.DeepSeq module

Remarks

Simon Marlow's book, Concurrent and Parallel Programming in Haskell, is outstanding and covers a multitude of concepts. It is also very much accessible for even the newest Haskell programmer. It is highly recommended and available in PDF or online for free.

Parallel vs Concurrent

Simon Marlow puts it best:

A parallel program is one that uses a multiplicity of computational hardware (e.g., several processor cores) to perform a computation more quickly. The aim is to arrive at the answer earlier, by delegating different parts of the computation to different processors that execute at the same time.

By contrast, concurrency is a program-structuring technique in which there are multiple threads of control. Conceptually, the threads of control execute “at the same time”; that is, the user sees their effects interleaved. Whether they actually execute at the same time or not is an implementation detail; a concurrent program can execute on a single processor through interleaved execution or on multiple physical processors.

Weak Head Normal Form

It's important to be aware of how lazy-evaluation works. The first section of this chapter will give a strong introduction into WHNF and how this relates to parallel and concurrent programming.