Cabbage.hs:
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))
When I compile (with ghc) I get this error message:
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)
I don't understand why a
is ambiguous. Surely the a
in line 7 is the same as the a
in line 6? How do I fix this?
Alternatively, is there a better way of declaring a per-instance constant?