[Haskell-cafe] Re: hamming distance allocation

Heinrich Apfelmus apfelmus at quantentunnel.de
Wed Apr 21 04:41:36 EDT 2010

Arnoldo Muller wrote:
> I believe these problems are one of the major sources of frustration for
> Haskell newbies. Things that could work in <X> language easily suddenly
> become problems in Haskell. When you overcome these issues then you feel
> happy again that you chose Haskell as the main programming language of your
> research project.

Well, the difference between <X> and Haskell is pretty much unavoidable.
If you care about space and time usage, then there is no way around
learning about lazy evaluation and Haskell's execution model.

> Is there any guide that explains more about the "bad consumption pattern".
> Are there any general rules defined to avoid these issues? It helped me to
> re-read the chapter on profiling in the Real World Haskell book to sorta
> understand the problem. Is there a more detailed definition of the problem
> than in RWH?

Two of the most commonly occurring patterns are

  1) foldl' vs foldl

  2) average xs = sum xs / length xs
     average = uncurry (/) . foldl' (\(!s,!n) x -> (s+x,n+1)) (0,0)

Other than that, most Haskell books offer a clear exposition of the
reduction model. For instance, there is

   Graham Hutton. Programming in Haskell, chapter 12.
   Richard Bird. Introduction to Functional Programming using Haskell
       2nd edition, chapter 7.

The wikibook contains some preliminary material, too.


Heinrich Apfelmus


More information about the Haskell-Cafe mailing list