[Haskell-cafe] How to split this string.

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Fri Jan 6 11:39:22 CET 2012

Steve Horne <sh006d3592 at blueyonder.co.uk> writes:

> On 05/01/2012 11:09, Brandon Allbery wrote:
>> On Thu, Jan 5, 2012 at 05:57, Steve Horne
>> <sh006d3592 at blueyonder.co.uk
>> <mailto:sh006d3592 at blueyonder.co.uk>> 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)


   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                                 Jon.Fairbairn at cl.cam.ac.uk

More information about the Haskell-Cafe mailing list