Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- | all decompositions of a string into multi-part (nonempty) pieces
- -- >>> parts "abc"
- -- [["abc"],["a","bc"], ["ab","c"], ["a","b","c"]]
- -- must not use drop, take, splitAt. must make use of list monad (listcomp/do notation)
- parts :: [a] -> [[[a]]]
- parts [] = []
- parts [x] = [[[x]]]
- parts l@(x:y:[]) = [[l], [[x], [y]]]
- parts l@(x:xs) = addElem (parts xs) x
- addElem :: [[[a]]] -> a -> [[[a]]]
- addElem [] e = [[[e]]]
- addElem l@(x:xs) e = [[e] : listOfStrings| listOfStrings <- l]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement