Laziness (was: [Haskell-cafe] Performance problem with random
derek.a.elkins at gmail.com
Sun Oct 14 18:29:57 EDT 2007
On Sun, 2007-10-14 at 18:14 -0400, Brandon S. Allbery KF8NH wrote:
> On Oct 14, 2007, at 17:54 , ntupel wrote:
> > Now my problem still is, that I don't know how to speed things up. I
> > tried putting seq and $! at various places with no apparent
> > improvement.
> > Maybe I need to find a different data structure for my random
> > module and
> > lazy lists are simply not working well enough here?
> Unfortunately I'm not so good at that myself. Even more
> unfortunately, my understanding is that randomly using seq and/or $!
> not only usually doesn't help, but can actually make things slower;
> and to do it right, you need to refer to the "simplified" Core
> Haskell code generated by GHC. And understanding *that* requires
> rather more familiarity with Core than I have. :/
A lot of times just unfolding a few evaluations by hand (perhaps
mentally) will point out issues readily and readily suggest there
solution. After a while you will know what kinds of things are
problematic and not write such code to begin with. Unfortunately, this
is not something widely and well understood and is not part of almost
any of the available educational material for Haskell. Programming in a
lazy language is more different than programming in an eager one than
almost any resource states.
More information about the Haskell-Cafe