Filtering list of tuples
haskell, list, syntax
Solution
In Haskell, you cannot iterate over a tuple like you can a list.
If the tuple only has two items, you can use `fst` to retrieve the first item of the tuple and `snd` to retrieve the second item.
One way to do what I think you want to do is this approach:
Prelude> let lst = [(1,2), (3,4)]
Prelude> filter ((==1).fst) lst
[(1,2)]
Which only returns the items in the list where the first element is equal to 1; of course, you can substitute `x` where I put 1.
To be a little more specific, `(==1).fst` first applies `fst` to the element in lst, then applies `(==1)` to the result of `fst` -- technically, the dot composes the two functions together.
Problem
New to Haskell and have a stumbling block. I'm trying to filter a list of tuples based on the first item. ``` filter (==(x,_)) lis ``` I get an illegal '_' error, but I'm not sure how I can get around it?