RFC: general sequences
ross at soi.city.ac.uk
Tue May 24 06:44:07 EDT 2005
On Mon, May 23, 2005 at 07:24:50PM +0200, Benjamin Franksen wrote:
> On Monday 23 May 2005 17:35, Ross Paterson wrote:
> > foldr_l :: (a -> b -> b) -> b -> Seq a -> b
> > foldr_l f z xs = case viewL xs of
> > EmptyL -> z
> > x :< xs' -> x `f` foldr_l f z xs'
> > The current definition is equivalent to [this] (but operates
> > directly on the internal structure).
> I wonder: Can a compiler optimize the above so that it is as efficient
> as the 'real' version? If not, why? If yes, everybody could easily
> create their own folds.
No, they're too different in structure for a compiler to work out the
transformation. People can still create their own folds -- they just
lose a constant factor over the insiders.
More information about the Libraries