I am new to Haskell and I stumbled upon this problem while playing around with classes.
So basically instead of defining functions inside a class, I want to define variables. In my case I'm defining a variable maxvalue inside the class Maxable. This worked just fine with Int. Now assuming a type a is an instance of Maxable, I want to define instance Maxable (Maybe a), which you can see in the third block of my code didn't work.
class Maxable a where
maxvalue :: a
-- This works fine
instance Maxable Int where
maxvalue = 2147483647
-- Error: Could not deduce (Maxable a1) arising from a use of ‘maxvalue’
instance Maxable a => Maxable (Maybe a) where
maxvalue = maxvalue :: a
What should I replace maxvalue = maxvalue :: a with so that "(Maybe a).maxvalue == a.maxvalue" ?