[Haskell-beginners] This is problem 2, chapter 4 RWH

Michael Litchard michael at schmong.org
Wed Jan 21 20:33:40 EST 2009

splitWith' :: (a -> Bool) -> [a] -> [[a]]
splitWith' p x = case takeUntil p x of
        [] -> []
        x' -> subset : splitWith' p x''
              where (subset, x'') = break p x'
   where takeUntil :: (a -> Bool) -> [a] -> [a]
         takeUntil p' = takeWhile q
              where q x = not (p' x)

It doesn't give me the right behavior though.
It should work like this:
splitWith' odd [2,2,1,4,4,3,6,6,5]
but it works like this instead

I'm pretty sure I modeled splitWith' on words, which is what the
exercise indirectly suggests.
Can someone help me step through this code to figure out what's wrong.
It looks right to me.

Michael Litchard

More information about the Beginners mailing list