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:
{-# LANGUAGE ParallelListComp #-}
myzip :: [a] -> [b] -> [(a, b)]
myzip xs ys = [(x, y) | x <- xs | y <- ys]
- The original type signature,
[a] -> [a] -> [(a, a)]
, meant that both lists had to have the same type of element. The Ord a
was superfluous, and just meant that certain types of elements were disallowed.
- The pattern
[x, _] <- list1
means that each element of list1
must be a two-element list. Use x <- list1
instead.
- The two list comprehensions are in series instead of parallel. Think of the comma as, "Take items from list1, then from list2" (series). Think of the two pipes as being parallel.
The difference between series and parallel:
> [[x, y] | x <- "abc", y <- "123"] -- series
["a1","a2","a3","b1","b2","b3","c1","c2","c3"]
> [[x, y] | x <- "abc" | y <- "123"] -- parallel
["a1","b2","c3"]