Cabbage.hs:Warum ist diese Art Variable mehrdeutig?
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))
Als ich (mit ghc) kompilieren bekomme ich diese Fehlermeldung:
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)
Ich verstehe nicht, warum a
nicht eindeutig ist. Sicher ist die a
in Zeile 7 die gleiche wie die a
in Zeile 6? Wie behebe ich das?
Oder gibt es eine bessere Möglichkeit, eine pro-Instanz konstant zu deklarieren?