I want to make a program that
- takes a character and a list of pairs of characters as arguments,
- returns the first element of the pair if it is equal to the input character, or returns the unchanged pair otherwise.
I have the following code:
lookUp :: Char -> [(Char, Char)] -> Char
lookUp a [] = []
lookUp a [(x,y),(xs,ys)]
| a == x = y : lookUp [(xs,ys)]
| otherwise = x : y : lookUp [(xs,ys)]
When I compile it, I get a lot of mistakes:
Couldn't match expected type 'char' with actual type [t0]
In an equation for 'lookUp'
and so on...
Sorry, I'm relatively new to Haskell. I'm pretty sure I made a mistake when dealing recursively with the tuple ([(x,y),(xs,ys)]
), but I don't know how to change it. Any ideas?
Either
data type. – SibiChar
) to the other ((Char,Char)
). Please clarify your specs. – jub0bs