Steve Horne <[email protected]> writes: > On 05/01/2012 11:09, Brandon Allbery wrote: >> On Thu, Jan 5, 2012 at 05:57, Steve Horne >> <[email protected] >> <mailto:[email protected]>> wrote: >> >> -- groupCut - Similar to groupBy, but where groupBy assumes an >> equivalence relation, >> -- groupCut takes a function that indicates where to cut. The >> two parameters to this >> -- function are always adjacent items from the list, and if the >> function returns True, >> -- a cut is done between the two items. >> >> span/break?
> Using those, the test function won't always be passed two > *adjacent* elements from the list. After all, they're based > on takeWhile and dropWhile, which take unary functions, > meaning an element has already been curried in (the starting > element of the group). > > That's probably how the current groupBy is implemented - the > approach that assumes an equivalence relation, giving > unexpected results when the By function isn't an equivalence > relation. groupBy is currently implemented using span. It strikes me that we ought to specify some properties for what we want. Start by defining: pairwiseInOrderBy p l = all (uncurry p) (l `zip` drop 1 l) giving all (pairwiseInOrderBy p) (groupCut p l) and we would want concat (groupCut p l) == l (all modulo nontermination side conditions). Anything else? -- Jón Fairbairn [email protected] _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
