{-# 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
这行得通。但是,如果我想为 EnumBox 添加一个 Class Enum 的实例,喜欢:
instance Enum EnumBox where
succ (EB s) = succ s
它失败并显示以下消息:
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
为什么第一个节目可以推断出第二个成功却不能?