
28 Mar
2009
28 Mar
'09
12:59 a.m.
Hi, I've been making my way through the exercises in the book "Real World Haskell". Below is my solution to an exercise asking for an implementation of groupBy in term sof a foldr. I haven't tested it extensively but is seems to work. GHCI rejects it though, if I uncomment the type signature for the 'step' function. Could someone please help me to understand why that is? Thanks, Jeff myGroupBy :: (a -> a -> Bool) -> [a] -> [[a]] myGroupBy p xs = foldr step [[]] xs where -- step :: a -> [ [ a ] ] -> [ [ a ] ] step x acc@( ys : yss ) | null ys = [ x ] : [] | p x ( head ys ) = ( x : ys ) : yss | ( p x ( head ys ) ) == False = [ x ] : acc