[Haskell-cafe] Shouldnt this be lazy too?

Jonathan Cast jcast at ou.edu
Mon Sep 24 15:26:32 EDT 2007


On Mon, 2007-09-24 at 17:35 +0100, Andrew Coppin wrote:
> Vimal wrote:
> > Hi all,
> >
> > I was surprised to find out that the following piece of code:
> >
> >   
> >> length [1..] > 10
> >>     
> >
> > isnt lazily evaluated! I wouldnt expect this to be a bug, but
> > in this case, shouldnt the computation end when the length function
> > evaluation goes something like:
> >
> >   
> >> 10 + length [11..]
> >>     
> >
> > ?
> >
> >   
> 
> In an ideal world, yes.
> 
> In this world, use "length (take 11 [1..]) > 10"...

not (null (drop 10 [1..])) is surely faster (not tested...)

jcc




More information about the Haskell-Cafe mailing list