Search code examples
haskelllist-comprehension

How does this Haskell List Comprehension evaluate?


I'm learning Haskell and I came across this example in relation to list comprehensions:
[x | xs <- [[(3,4)],[(5,4),(3,2)]], (3,x) <- xs]
The answer given is:
[4,2].

Why isn't the answer [(3,4),(3,2)]?


Solution

  • Matching (3,x) against (3,4) gives x = 4. If you wanted (3,4), you should write [(3,x) | ...].