[Haskell-cafe] groupBy huh?

Jacek Generowicz jacek.generowicz at cern.ch
Fri Mar 4 02:09:13 CET 2011


On 2011 Mar 4, at 01:39, Marc Weber wrote:

> Excerpts from Jacek Generowicz's message of Fri Mar 04 00:18:07  
> +0000 2011:
>> Prelude Data.List> groupBy (<) [1,2,3,2]
>> [[1,2,3,2]]
> This is wired. However if you think about the algorithm always using  
> the
> first element of a list and comparing it against the next elements you
> get
>
> 1 < 2 ok, same group
> 1 < 3 dito
> 1 < 2 dito
> Thus you get [[1,2,3,2]]


OK, that works, but it seems like a strange choice ...


On 2011 Mar 4, at 01:47, Daniel Fischer wrote:

> On Friday 04 March 2011 01:18:07, Jacek Generowicz wrote:
>>
>> What am I missing?
>>
>
> That groupBy expects an equivalence relation

... Bingo! Now it makes sense.

> (iirc, that was documented some time, seems to be gone, there's only  
> a hint left at the docs for group
> "equality test").

Hrrrrmph. In my opinion, explicitly including the words "equivalence  
relation" would immensely improve the documentation.


Thank you for you clarifications, gentlemen.




More information about the Haskell-Cafe mailing list