Created
March 7, 2012 13:30
-
-
Save jason2506/1993135 to your computer and use it in GitHub Desktop.
[Haskell Practice] split a list into sub-lists using a set of separators.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
split :: (Eq a) => [a] -> [a] -> [[a]] | |
split _ [] = [[]] | |
split sep (list_head:list_tail) = | |
if list_head `elem` sep | |
then []:splited_tail | |
else (list_head:(head splited_tail)):(tail splited_tail) | |
where splited_tail = split sep list_tail | |
main = do | |
putStr (show (split " " "this is a book")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment