3
{-# 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

最初のショーは推測できるのに、2 番目の成功は推測できないのはなぜですか?

4

1 に答える 1