[Haskell-beginners] Important coding guideline and library proposal

Daniel Fischer daniel.is.fischer at web.de
Sun Nov 22 14:55:56 EST 2009

Am Sonntag 22 November 2009 20:33:21 schrieb Stephen Tetley:
> Hi Daniel
> Hmm, maybe the docs in Data.List should say that length is recursively
> calculated.

I never noticed the docs didn't say anything about the complexity of length.
That should indeed be mentioned.

> I know you can view the source from Haddock, and its also
> obvious once you think of list as being defined by an algebriac type,
> but lists in other languages (read OO) often have track length as part
> of the ADT making it constant time to get hold of.

Which of course is not easy for infinite lists, even harder for lists of which you don't 
know yet whether they're finite or not (list of prime-twins, e.g.).

> Best wishes
> Stephen
> 2009/11/22 Daniel Fischer <daniel.is.fischer at web.de>:
> > Guideline:
> >
> > NEVER, *never ever*, use 'length' ***unless you really want to know the
> > exact length of a list***
> >
> > Proposal:
> > rename 'length' to
> > 'yesIReallyWantToKnowTheExactLengthOfThisListSoPleaseCalculateItForMe' to
> > reduce performance bugs caused by naive uses of length.

More information about the Beginners mailing list