(省略) のように定義された GADT があります。
{-# LANGUAGE StandaloneDeriving #-}
data D t where
C :: t -> D t
R :: D b -> D (Either a b)
deriving instance Show t => Show (D t)
コンパイラは、R の Show を導出できないと正しく不平を言います。この場合、(Either ab) は Show クラスですが、b が Show クラスである場合、これが true であることを知ることはできません。エラーメッセージは、
Could not deduce (Show b) from the context (t ~ Either a b)
arising from a use of `showsPrec' at tmp.hs:37:0-37
Possible fix: add (Show b) to the context of the constructor `R'
In the second argument of `(.)', namely `(showsPrec 11 b1)'
In the second argument of `showParen', namely
`((.) (showString "R ") (showsPrec 11 b1))'
In the expression:
showParen ((a >= 11)) ((.) (showString "R ") (showsPrec 11 b1))
When typechecking a standalone-derived method for `Show (D t)':
showsPrec a (C b1)
= showParen ((a >= 11)) ((.) (showString "C ") (showsPrec 11 b1))
showsPrec a (R b1)
= showParen ((a >= 11)) ((.) (showString "R ") (showsPrec 11 b1))
存在型 b に対して "Show b => Show (D (Either ab))" のようなものを言うか、"(Show a, Show b) = 含意をアップグレードできるようにする必要があるようです。 > Show (Eith ab)」なので、双方向です。
どうもありがとう!
(タイトルや説明は自由に削除してください。)