
21 Jan
2009
21 Jan
'09
8:33 p.m.
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] [[2,2],[4,4],[6,6]] but it works like this instead [[2,2]] 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