[Haskell-beginners] Is it possible to implement groupBy using folds?

Zhi-Qiang Lei zhiqiang.lei at gmail.com
Thu Jun 16 15:55:37 CEST 2011


Hi,

The source code of groupBy shows that groupBy does not go through every element. Is it really possible to implement it using folds? Thanks.

-- | The 'groupBy' function is the non-overloaded version of 'group'.
groupBy                 :: (a -> a -> Bool) -> [a] -> [[a]]
groupBy _  []           =  []
groupBy eq (x:xs)       =  (x:ys) : groupBy eq zs
                           where (ys,zs) = span (eq x) xs


Best regards,
Zhi-Qiang Lei
zhiqiang.lei at gmail.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110616/42a5e19b/attachment.htm>


More information about the Beginners mailing list