[Haskell-cafe] groupBy without Ord?
Kim-Ee Yeoh
ky3 at atamo.com
Sat Mar 22 17:40:05 UTC 2014
On Sat, Mar 22, 2014 at 11:51 PM, martin <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
where (ys,zs) = span (eq x) xs
and replace 'span' by 'partition' you'd get what you want.
You'd need a new name for your different groupBy of course.
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140323/ab363089/attachment.html>
More information about the Haskell-Cafe
mailing list