[Haskell-beginners] Partition a list recursively

Alexandre Delanoë alexandre+haskell at delanoe.org
Tue Nov 3 10:12:31 UTC 2015


Hello,
I am looking for such function:

function :: Ord a => [a] -> [a] -> [[a]]
function [1,3,6] [0..6] == [[0,1],[2,3],[4,5,6]]

Question: does it exist already ? If no, continue:

Let:

partIt :: Ord a => a -> [a] -> [[a]]
partIt m xs = [takeWhile (<= m) xs, dropWhile (<= m) xs]
example:
partIt 1 [0..5] == [[0,1],[2,3,4,5]]

Question: How to define recursively partIt
1) with a list as parameter ?
2) recursively on the second part of the list ?

Thanks for help,

-- 
	Alexandre Delanoë


More information about the Beginners mailing list