Gmane
Picon
From: Henning Thielemann <lemming <at> henning-thielemann.de>
Subject: Data.List.groupBy with non-transitive equality predicate
Newsgroups: gmane.comp.lang.haskell.libraries
Date: 2007-08-29 20:02:53 GMT (37 weeks, 1 day, 7 hours and 24 minutes ago)

I was used to use groupBy to split a list before every element that
satisfies a predicate. E.g. splitting before every capital

Prelude> groupBy (\_ c -> not $ Char.isUpper c) "Hello World"
["Hello ","World"]

I also wanted to use this for splitting after specific elements.
But this fails. I get

Prelude> groupBy (\c _ -> c /= ',') "1, 2, 3, 4"
["1, 2, 3, 4"]

but I wanted
["1,", " 2,", " 3,", " 4"]

 I assumed that 'groupBy' would compare adjacent elements, but it seems to
compare the leading element of each block with subsequent elements. Since
the documentation doesn't tell which elements are actually compared it
seems to assume that the comparison is commutative and transitive. Maybe
this point should be made clearer.
 Additionally I think that comparing neighbouring elements is a useful
behaviour and I suggest an according variant of 'groupBy' for Data.List.
Opinions?