Cabbage.hs:¿Por qué este tipo de variable es ambiguo?
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))
Cuando compilo (con GHC) me sale este mensaje de error:
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)
No entiendo por qué a
es ambigua. Sin duda, el a
en la línea 7 es el mismo que el a
en la línea 6? ¿Cómo puedo solucionar esto?
Alternativamente, ¿existe una forma mejor de declarar una constante por instancia?