So I have to make a function that finds a pair with its 1st letter and returning the 2nd letter.
I actually found one answer but with the map function and I couldn't get it.
lookUp :: Char -> [(Char, Char)] -> Char
lookUp x [] = x
lookUp x ( ( st,nd ): rst) | st == x = nd
| otherwise = lookUp x rst
And I get this message:
No instance for (Show ([(Char, Char)] -> Char))
arising from a use of `print'
Possible fix:
add an instance declaration for (Show ([(Char, Char
In a stmt of an interactive GHCi command: print it
Your code is fine, you just need to supply all the arguments at the ghci prompt, eg
Should give you 'q'.
It's complaining that it can't show a function. Any time it says it doesn't have a Show instance for something with -> in, it's complaining it can't show a function. It can only show the result of using the function on some data.
When you give it some, but not all data, Haskell interprets that as a new function that takes the next argument, so
is a function that will take a list of pairs of characters and give you a character. That's what it was trying to show, but couldn't.
By the way, almost every time you get a "No instance for..." error, it's because you did something wrong with the arguments - missed some out, put them in the wrong order. The compiler's trying to be helpful by suggesting you add an instance, but probably you just need to check you supplied the write type of arguments in the right order.
Have fun learning Haskell!
It seems that you typed something like this in ghci:
An expression like
lookUp 'c'
is a partial evaluation / curried form of thelookUp
function. It's type is:which is the exact type that ghci says there is no Show instance for.
To test your function, be sure to supply both
x
and the the list ofChar
pairs: