[Haskell-beginners] Why doesn't ghci load this?

Jeff Lasslett jeff.lasslett at gmail.com
Sat Mar 28 00:59:23 EDT 2009


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





More information about the Beginners mailing list