I have an assignment in which I need to check if a given Int is the first element of any tuple in a list of tuples. For example, if I want to check if 1
is the first element of any tuple on the list [(2,3), (3,3), (2,7)]
it should return False
, however, if I want to check if 1
is the first element on the list [(2,2), (1,2), (3,4)]
, it should return True
.
This is my attempt:
isFirst :: (Eq a) => a -> [(a,b)] -> Bool
isFirst _ [] = False
isFirst x [(y1, y2)] = x == y1
isFirst x ((y1, y2):l) = if y1 : isFirst l then True
else False
I'm still new to Haskell so I really have no clue if I'm even close to the right solution, Thanks for your help!