Skip to content

Instantly share code, notes, and snippets.

@jason2506
Created March 7, 2012 13:30
Show Gist options
  • Save jason2506/1993135 to your computer and use it in GitHub Desktop.
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.
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