I am looking for a way to merge a list of lists with a singular list, that keeps the structure of the list of lists. I.e. a function foo that works like this:
foo :: [[a]] -> [b] -> [[(a,b)]]
> foo [[1],[2,2,3],[7,8]] [0..]
[[(1,0)],[(2,1),(2,2),(3,3)],[(7,4),(8,5)]]
(Or the other way around with the arguments)
foo :: [b] -> [[a]] -> [[(b,a)]]
> foo [0..] [[1],[2,2,3],[7,8]]
[[(0,1)],[(1,2),(2,2),(3,3)],[(4,7),(5,8)]]
Of course, if we know that each list is equal in length, this function could easily be created by:
import Data.List.Split (chunksOf)
foo :: [[a]] -> [b] -> [[(a,b)]]
foo xs ys = chunksOf n $ zip (concat xs) ys
where
n = length $ head xs
But how can this function be done in the more general case of unequal list lengths?