I have this code that does not compile. I'd like to understand why it can not deduce the types.
module Main where
data Combiner a = Combiner a (a -> Int)
comb = Combiner 3 (\x -> 5)
class HasValue a where
getValue :: Int
instance HasValue Combiner where
getValue (Combiner x f) = f x
main = print $ getValue comb
Here's the error:
main.hs:8:3: error:
• Could not deduce (HasValue a0)
from the context: HasValue a
bound by the type signature for:
getValue :: HasValue a => Int
at main.hs:8:3-17
The type variable ‘a0’ is ambiguous
• In the ambiguity check for ‘getValue’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
When checking the class method:
getValue :: forall a. HasValue a => Int
In the class declaration for ‘HasValue’
getValue
bea -> Int
? – Willem Van Onsem