Luke Collins
Luke Collins

Reputation: 1463

Zip over a 2D List in 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.

Upvotes: 3

Views: 877

Answers (1)

leftaroundabout
leftaroundabout

Reputation: 120711

zip' = zipWith zip

Nice, isn't it?

Upvotes: 11

Related Questions