我正在尝试将 Maybe 值转换为 Char。我收到以下错误,尽管我尽了最大努力,但我无法弄清楚如何纠正这个错误。
convertmaybe.hs:18:22:
No instance for (ToChar a)
arising from a use of `toChar'
In the expression: toChar a
In an equation for `showMaybe': showMaybe (Just a) = toChar a
Failed, modules loaded: none.
这是代码:
class ToChar a where
toChar :: a -> Char
instance ToChar Char where
toChar = id
instance ToChar Int where
toChar = head . show
showMaybe :: Maybe a -> Char
showMaybe Nothing = ' '
showMaybe (Just a) = toChar a
我在这里做错了什么?