{-# 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喜欢:存在量化类型无法在类型上下文中推导
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
为什么首秀可以推断出,但第二SUCC不能?
好像你忘了运用'EB'为'SUCC s'。 – Vitus
你说得对。我想念包装。 – highfly22