I am trying to return the second element of a tuple that has the same first element as the char.
If there isn't a tuple with same char as it's first element then I want to return 0
There can only be 0 or 1 tuples with the same char as the char given, hence taking the head of the [Int] returned by the list comprehension.
this is the code I wrote, the error is when I try to check whether a tuple (c,) is in the list of tuples with 'elem (c,) m'
type Mem = [(Name,Int)]
getVal :: Char -> Mem -> Int
getVal c m
| elem (c,_) m = head [snd n | n <- m, fst n == c]
| otherwise = 0
A fix for that problem, or a suggestion of a better way to do this would be recieved gratefully!
Thanks