Laziness and parallelism

  • I associate the term “automatic” with Haskell’s memory management because there’s no direct way to “decree” (in ordinary Haskell) that some particular expression “shall” work without it.

  • In contrast, laziness in Haskell can be “modulated” (hence the term non-strict semantics) - I can use (ordinary Haskell) bang annotations on types:

    data Complex a = !a :+ !a
    

    …or the confusingly-named primitive seq function (which isn’t actually sequential). Using -XStrict takes this to the extreme by inserting calls to seq throughout the modules it’s used on.

That is why I chose the phrase “lazy by default” for my initial post about parallelism - Haskell can be written “lazily”, but that’s rarely seen these days.


Parallel Haskell is indeed here and it’s great (which makes Haskell worth recommending for commercial use […])

I believe one LaurentRDC would completely agree with you!

…but some aren’t quite satisfied:

Completing #240 would then present an opportunity for (Glasgow) Haskell - since it already goes to the trouble of identifying suitable candidate expressions for speculative evaluation:

2.7. Version 9.6.7 — Glasgow Haskell Compiler 9.6.7 User's Guide

Added new flags -fspec-eval and -fspec-eval-dictfun to allow switching off speculative evaluation […].

a parallel version of GHC could (at least to begin with) just annotate some of those candidates with calls to par, possibly depending on how many tasks the hardware can support. Since multithreading would be enabled by default in GHC, so would this elementary form of parallelism.

(…hrm: I thought this was a private topic.)

2 Likes