[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Left- and right-ness of folds

This page is part of the web mail archives of SRFI 44 from before July 7th, 2015. The new archives for SRFI 44 contain all messages, not just those from before July 7th, 2015.



On Sat, Oct 25, 2003 at 12:13:33PM -0700, Bradd W. Szonye wrote:
> > Bradd W. Szonye wrote:
> >> Even with the "right-associative" definition, a right fold is still
> >> not possible for an infinite sequence, because the fold will not
> >> halt. It will diverge before you can even use the initial value. You
> >> first need to select a finite subset so that you can apply the
> >> initial value in the fold.
> 
> scgmille@xxxxxxxxxxxxxxxxxx wrote:
> > It would still be defined for said collections however.  The fact that
> > it may not halt is a pitfall for the programmer that attempts it.
> 
> That's a big pitfall! A right-fold on an infinite sequence will diverge
> before the folding function ever gets called. I think it's a bad idea to
> provide an interface that is "broken by design" like that -- it cannot
> possibly function correctly.

Its not really.  collection-fold-right will raise an error if applied to
an infinite collection.  Would it placate you if it was required to 
raise an error with truely infinite collections?  Real infinite 
collections's fold-rights would then error immediately rather than after 
running out of memory.

	Scott

Attachment: pgpSq5rZ0MrKU.pgp
Description: PGP signature