Generalize groupBy in a useful way?
duncan.coutts at worc.ox.ac.uk
Fri Sep 5 08:23:11 EDT 2008
On Fri, 2008-09-05 at 08:33 +0100, Ross Paterson wrote:
> On Fri, Sep 05, 2008 at 07:06:54AM +0000, Bart Massey wrote:
> > I think it would be better to expand the definition of
> > groupBy such that the equality test is applied only to
> > adjacent elements (with the arguments in proper order).
> I agree:
> We should do it this time. (Probably too late for 6.10, though.)
Yes, this behaviour surprised us when we were re-implementing the list
library (as part of the stream fusion stuff). We assumed this was the
behaviour and didn't catch it until we ran our quickcheck tests with
randomly generated predicates.
There's also a more efficient version that can be implemented if one is
allowed to be slightly stricter and not return a group until the end of
the group is encountered, but that's obviously not suitable for
Data.List. (But it would be interesting if we could use RULES that could
match on strictness properties.)
More information about the Libraries