Hélder Moreira
Hélder Moreira

Reputation: 181

Check first on tuple to see if matches with parameter

i have this doubt, and can't find an answer to my problem.

the bit of haskell code that does not want to be compiled :

type Prim = (String,String)

primeiros :: [Prim] -> [String]
primeiros [] = []
primeiros (a:xs) = fst a: primeiros xs 

nosPrimeiros :: String -> [Prim] -> Bool
nosPrimeiros x [] = False
nosPrimeiros x ((a,b):xs) = if (x == primeiros (a,b) ) then True
                                                       else nosPrimeiros x xs

basically what the first function does is

primeiros [("one","guy"),("yes","man"),("works","not")]
> ["one","yes","works"]

And the second function, checks if string "one" is embed on the first position of each tuple, if it is at least inside one, gives true, if "one" is not in the first position of at least one , gives false.

nosPrimeiros "one" [("one","guy"),("yes","man"),("works","not")]

True

What fails? This is basic Haskell stuff, not being able to do this drives me nuts...

Thank you very much for your help.

Upvotes: 1

Views: 104

Answers (1)

if (x == primeiros (a, b) ) should be if (x == a).

Upvotes: 1

Related Questions