[Haskell-cafe] GHC predictability

Don Stewart dons at galois.com
Wed May 14 14:28:00 EDT 2008

> Brandon S. Allbery KF8NH wrote:
> >
> >On 2008 May 13, at 17:01, Andrew Coppin wrote:
> >
> >>That definition of mean is wrong because it traverses the list twice. 
> >>(Curiosity: would traversing it twice in parallel work any better?) 
> >>As for the folds - I always *always* mix up

Yes, using parallelism does work. It turns the naive definition into
one which traverses the list on two cores at the same time, so the
garbage collector does get clean up the list as each core races along

    mean ls = count `par` (total/count)
      where count = fromIntegral (length ls)
            total = foldl' (+) 0 ls

It is kind of amazing how parallelism and laziness enable the naive
definition to fall out as much the same as the explicitly recursive

--  Don

More information about the Haskell-Cafe mailing list