[Haskell-cafe] Re: Why purely in haskell?

David Roundy droundy at darcs.net
Thu Jan 10 14:23:04 EST 2008


On Thu, Jan 10, 2008 at 10:10:21AM -0800, Don Stewart wrote:
> rendel:
> > jerzy.karczmarczuk at info.unicaen.fr wrote:
> > >>Although it could be argued that laziness is the cause of some very 
> > >>obscure bugs... <g> Niko
> > >
> > >Example, PLEASE.
> > 
> > Prelude> sum [1..1000000]
> > *** Exception: stack overflow
> > 
> > Prelude> Data.List.foldl' (+) 0 [1..1000000]
> > 500000500000
> 
> See,
>   http://hackage.haskell.org/trac/ghc/ticket/1997
>
> Strictness for for atomic numeric types is inconsitently applied 
> across the base library. Fixing the inconsitencies would let 
> fix a range of similar issues.

Having followed this discussion, I agree with your analysis, but also think
that rendel has chosen a good example of a pretty obscure bug caused by
laziness in code written by folks who are actually decent Haskell
programmers.  It's unfortunate that there's no way to include strictness
behavior in function types (at least that I'm aware of), so one has to rely
on possibly-undocumented (and certainly never checked by a compiler)
strictness behavior of many functions in order to write truly correct
code.

I wish there were a nice way around this issue (but can't really even
imagine one).
-- 
David Roundy
Department of Physics
Oregon State University


More information about the Haskell-Cafe mailing list