What is the zip function in Haskell?
Overview
The zip function is used to merge two lists in Haskell. It will merge with the elements present at the same position in both lists.
Syntax
zip list1 list2
Parameters and return value
It takes two lists as parameters and returns a tuple or list.
Let’s have a look at the example below.
Example
main::IO()main = do--usage of zip functionprint( zip ['x', 'y', 'z'][12, 13, 25] )
Explanation
- Line 5: We use the
zipfunction to merge the given two lists. We will pass the given two lists as parameters to the function, and it will return a list after merging the given lists.