Question About lists
Shlomi Fish
shlomif@vipe.technion.ac.il
Wed, 1 Jan 2003 12:17:10 +0200 (IST)
On Wed, 1 Jan 2003, Andrew J Bromage wrote:
> G'day all.
>
> On Mon, Dec 30, 2002 at 01:47:37PM -0600, Artie Gold wrote:
>
> > One suggestion, though is that you're working too hard; there's really
> > no reason to define a locally defined function. The much simpler:
> >
> > long [] = 0
> > long (x:xs) = 1 + long xs
> >
> > will do quite nicely.
>
> It has quite different performance characteristics, though. In
> particular, this uses O(n) stack space whereas the accumulator one
> uses O(1) stack space.
>
This is assuming Haskell is properly tail-recursive. However, as far as I
was told due to the lazy evaluation that is not the case for such
functions.
Regards,
Shlomi Fish
> Cheers,
> Andrew Bromage
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>
----------------------------------------------------------------------
Shlomi Fish shlomif@vipe.technion.ac.il
Home Page: http://t2.technion.ac.il/~shlomif/
He who re-invents the wheel, understands much better how a wheel works.