Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zip over a 2D List in Haskell

Tags:

list

haskell

I want to combine two 2-dimensional lists in Haskell using zip, i.e. achieve something like this

[[1,2,3],           [[10, 11, 12],         [[(1, 10), (2, 11), (3, 12)],
 [4,5,6],   `zip'`   [13, 14, 15],   ->     [(4, 13), (5, 14), (6, 15)],
 [7,8,9]]            [16, 17, 18]]          [(7, 16), (8, 17), (9, 18)]]

without using any functions outside the Prelude. Is there a way this can be done, using map perhaps? The problem is that one cannot map zip over two lists.

like image 257
Luke Collins Avatar asked Nov 20 '25 09:11

Luke Collins


1 Answers

zip' = zipWith zip

Nice, isn't it?

like image 141
leftaroundabout Avatar answered Nov 23 '25 03:11

leftaroundabout