[Haskell-cafe] groupBy without Ord?

martin martin.drautzburg at web.de
Sat Mar 22 18:29:02 UTC 2014


Am 03/22/2014 06:40 PM, schrieb Kim-Ee Yeoh:
> 
> On Sat, Mar 22, 2014 at 11:51 PM, martin <martin.drautzburg at web.de <mailto:martin.drautzburg at web.de>> wrote:
> 
>     How can I groupBy a List whose elements are only instances of Eq but not of Ord?
> 
> 
> If you take a look at the code for groupBy:
> 
> groupBy           :: (a -> a -> Bool) -> [a] -> [[a]]
> groupBy _  []     =  []
> groupBy eq (x:xs) =  (x:ys) : groupBy eq zs

Cool!

I have a database background and the SQL "group by" does of course not assume any ordering. So I often wonder, where you
would use Haskell's groupBy WITHOUT sorting first, but I assume there are situations, where this is useful.



More information about the Haskell-Cafe mailing list