[Haskell-cafe] A bug of groupBy implement

Matthijs Kooijman matthijs at stdin.nl
Mon Dec 7 12:19:37 EST 2009


Hi,

> I have tested it in GHC 6.10.4 (Win XP) and GHC 6.8.3 (Linux), both give the wrong result (categaried):
> 
>         7 <= 3 ?: False
>         3 <= 5 ?: True
>         3 <= 9 ?: True
>         3 <= 6 ?: True
>         3 <= 8 ?: True
>         3 <= 3 ?: True
>         3 <= 5 ?: True
>         3 <= 4 ?: True
> [[7],[3,5,9,6,8,3,5,4]]
What exactly is wrong with this result? All of the above comparisons seem to
get the right result, and they say 7 is not in the same categorie as 3, but
all other numbers are in the same category as 3. So the returned list looks ok
too.

Perhaps you had expected another output list (please tell us what you think
you've found a bug!)? In fact, it seems that any output list would have been
correct, since you're using a comparison function that is not symmetrical.

In other words, you're say 7 should be in the same category as 3, but 3 should
not be in the same category as 7. Since nothing is guaranteed about the order
in which groupBy compares elements, any grouping could be achieved by letting
groupBy choose the "right" ordering.

So, it seems your comparison function is wrong since it does not satisfy the
(unwritten) requirement of symmetry?

Gr.

Matthijs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20091207/efe27fcc/attachment.bin


More information about the Haskell-Cafe mailing list