J'essaie de déclarer mes propres données avec la conversion appropriée en classe. Mon code ressemble à ceci:Ambiguïté entre la classe Haskell Num et ma classe de type show
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
Mais GHC (7.0.3) se met en colère et dit:
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)
signature de type explicite (comme 3 :: Int) résout le problème, mais il est très pratique .
Standard "Show" fonctionne très bien, et selon le manuel, il est déclaré exactement de la même manière.
Pourquoi Show standard fonctionne, mais pas ma classe? Ai-je manqué quelque chose?
P.S .: Explicite "default (Int)" ne résout pas cela.