
22 Oct
2007
22 Oct
'07
9:50 a.m.
Hi We certainly need a function to split a list into sections. Whether it be wordsBy, or something like linesBy, or some new split variant.
wordsBy :: (a -> Bool) -> [a] -> [[a]] wordsBy p s = case dropWhile p s of [] -> [] s':rest -> (s':w) : wordsBy p s'' where (w, s'') = break p rest
You are still over by one test. Try instead: wordsBy :: (a -> Bool) -> [a] -> [[a]] wordsBy p s = case dropWhile p s of [] -> [] s':rest -> (s':w) : wordsBy p (drop 1 s'') where (w, s'') = break p rest The supero paper (http://www-users.cs.york.ac.uk/~ndm/supero/) has a very short explanation of this. Thanks Neil