You can think of this function as choosing for each place between two elements of the list whether to include separation there. Therefore, for starters, there should be 2 n-1 sections for a list of n-elements: you can use this as a quick check for a possible solution.
(, , ), .
:
separate :: [a] -> [[[a]]]
separate [] = [[]]
: , . .
, , , :
separate :: [a] -> [[[a]]]
separate [] = [[]]
separate (x:xs) = let recur = separate xs
in undefined -- TODO
, . , , . , :
separate :: [a] -> [[[a]]]
separate [] = [[]]
separate (x:xs) = let recur = separate xs
split = undefined -- TODO
noSplit = undefined -- TODO
in split ++ noSplit
, x? recur, [x] :
separate :: [a] -> [[[a]]]
separate [] = [[]]
separate (x:xs) = let recur = separate xs
split = do
partition <- recur
return $ [x] : partition
noSplit = undefined -- TODO
in split ++ noSplit
? ! recur x :
separate :: [a] -> [[[a]]]
separate [] = [[]]
separate (x:xs) = let recur = separate xs
split = do
partition <- recur
return $ [x] : partition
noSplit = do
(y:ys) <- recur
return $ (x:y):ys
in split ++ noSplit
:
*Temp> separate "123"
[["1","2","3"],["1","23"],["12","3"],["123"]]