[Haskell-cafe] Data.List.Split

Adam Vogt vogt.adam at gmail.com
Sun Dec 14 00:35:02 EST 2008

* On Saturday, December 13 2008, Gianfranco Alongi wrote:

>that groupBy (==) [1,2,1,2] should give

That result happens with:

> sortedGroups = group . sort

That composition is pretty, unlike those splitting functions. I don't know 
if manually fusing sort and group helps performance at all though.

Making groups by comparing with the previous element, or the first element 
of the current group is occasionally useful: (this does the former)

> groupIncDiff p = uncurry (:) . foldr w ([],[])
>     where w n ([],a) = ([n],a)
>           w n ((x:xs),a) | p x n = (n:x:xs,a)
>                          | otherwise = ([n],(x:xs):a)

(in case somebody feels like assembling the apparently numerous was to 

On another note, is there much use of such simple library functions: does 
concatMap, for instance, save anything other than a couple parantheses, or 
does (concat . map) not necessarily get optimized into the same thing?


More information about the Haskell-Cafe mailing list