I’ve got a function here that is meant to look through a list of tuples and find the second value in the tuple by taking in the first value. Here’s the function so far:
lookup :: String -> [(String,String)] -> String
lookup _ _ [] = "Not found"
lookup x y zs = if (notFound x zs)
then "Not found"
else (head [b | (a,b) <- zs, (a==x)])
The notFound function just returns a Bool as true if there is no tuple containing the given first string. Problem is, I get this type error in Hugs:
ERROR "find.hs" (line 22): Type error in explicitly typed binding
*** Term : lookup
*** Type : String -> [(String,String)] -> [a] -> String
*** Does not match : String -> [(String,String)] -> String
I’m thinking it’s something to do with the dummy “Not found” value having a different type to the string from the generated list, but I’m not sure.
I think your explicit type-declaration is wrong. You have:
but I think it should be
Actually, after taking another look at it, it looks like you’re not using the 2nd parameter “y”. So you could remove it and the underscore like so
This will allow you to keep the type declaration you have.