-- eg. myzip [’a’, ’b’, ’c’] [1, 2, 3, 4] -> [(’a’, 1), (’b’, 2), (’c’, 3)]
myzip :: Ord a => [a] -> [a] -> [(a,a)]
myzip list1 list2 = [(x,y) | [x, _] <-list1, [y,_] <-list2 ]
I get this error message:
Occurs check: cannot construct the infinite type: a = [a]
When generalising the type(s) for `myzip'
Failed, modules loaded: none.
There are three problems: One is the pattern match, one is the type signature, and one is the nature of the list comprehension. Here is a corrected version:
[a] -> [a] -> [(a, a)], meant that both lists had to have the same type of element. TheOrd awas superfluous, and just meant that certain types of elements were disallowed.[x, _] <- list1means that each element oflist1must be a two-element list. Usex <- list1instead.The difference between series and parallel: