I have a function like this:
selectValue1 :: Int -> [(Int,Int)] -> [Int]
selectValue1 a [(x,y)]= [ y |(x,y)<-[(x,y)],x<-(x,y),x==a ]
what i want to do is to pass a tuple list to the function and take the second item in the tuple if the first item in the tuple matches with the input a.But this function give me an error:
Type error in generator
*** Term : (x,y)
*** Type : (Int,Int)
*** Does not match : [a]
why this happens??How can do the above task?? Any solutions?? Thank you all..:)
selectValue1 a xs = [ y | (x,y) <- xs, x == a ]
First you shouldn't have pattern matched in the left hand side of the definition. You're just giving a name to your argument -- looking inside it, so to speak, can all happen in the list comprehension. Second, x <- (x,y) makes no sense. The rhs of the arrow in a list comprehension is always a list. In this case, it was doing nothing, so I removed it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With