Cabbage.hs:Perché questo tipo di variabile è ambigua?
module Cabbage where
class Cabbage a
where foo :: a -> String -- the parameter is only present for its type,
-- the parameter value will be ignored
bar :: String -> a
quux :: Cabbage a => String -> a
quux s = bar (s ++ foo (undefined :: a))
Quando compilo (con GHC) ottengo questo messaggio di errore:
Cabbage.hs:7:19:
Ambiguous type variable `a' in the constraint:
`Cabbage a' arising from a use of `foo' at Cabbage.hs:7:19-38
Probable fix: add a type signature that fixes these type variable(s)
Non capisco il motivo per cui a
è ambigua. Sicuramente il a
nella riga 7 è lo stesso del a
nella riga 6? Come posso risolvere questo?
In alternativa, c'è un modo migliore per dichiarare una costante per istanza?