{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable #-}
import Data.Typeable;
data EnumBox = forall s. (Enum s, Show s) => EB s
deriving Typeable
instance Show EnumBox where
show (EB s) = "EB " ++ show s
This works. But if I want to add a instance of Class Enum for EnumBox likes:
instance Enum EnumBox where
succ (EB s) = succ s
It fails with the message:
Could not deduce (s ~ EnumBox)
from the context (Enum s, Show s)
bound by a pattern with constructor
EB :: forall s. (Enum s, Show s) => s -> EnumBox,
in an equation for `succ'
at typeclass.hs:11:9-12
`s' is a rigid type variable bound by
a pattern with constructor
EB :: forall s. (Enum s, Show s) => s -> EnumBox,
in an equation for `succ'
at typeclass.hs:11:9
In the first argument of `succ', namely `s'
In the expression: succ s
In an equation for `succ': succ (EB s) = succ s
Why the first show can be deduced but the second succ cannot?
You're only problem is that
succ
has the typeSo you need
Just boxing it up again.
Also you'll probably want
As this is the minimum definition of completeness, since