No instance for (Show ([(Char, Char)] -> Char))

后端 未结 2 1992
闹比i
闹比i 2021-01-06 05:48

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\'

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-06 06:00

    It seems that you typed something like this in ghci:

    *Main> lookUp 'c'
    

    An expression like lookUp 'c' is a partial evaluation / curried form of the lookUp function. It's type is:

    *Main> :t lookUp 'c'
    lookUp 'c' :: [(Char, Char)] -> Char
    

    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 of Char pairs:

    *Main> lookUp 'c' [ ('a','A'), ('b','B'), ('c','C') ]
    'C'
    

提交回复
热议问题