我想用适当的转换类声明我自己的数据。我的代码如下所示:Haskell Num类和我的类似节目之间的歧义
data SomeData = SInteger Integer | SElse deriving Show
class Some a where
toSome :: a -> SomeData
instance Some Int where toSome = SInteger . toInteger
main :: IO()
main = print $ toSome 3
但GHC(7.0.3)变得恼怒地说:
Ambiguous type variable `a0' in the constraints:
(Some a0) arising from a use of `toSome'
at minimal_broken.hs:11:16-21
(Num a0) arising from the literal `3' at minimal_broken.hs:11:23
Probable fix: add a type signature that fixes these type variable(s)
显式类型签名(如3 ::智力)修复该问题,但它是非常不方便。
标准的“显示”工作得很好,根据手册它的声明完全一样。
为什么标准显示作品,但我的班级没有?我错过了什么?
P.S .:明确的“default(Int)”不能解决这个问题。