我有一个递归数据定义:
data Checked a = forall b. Checked (Either (Warning, Maybe (Checked b), a) a)
我需要递归地定义 Show:
instance (Show a) => Show (Checked a) where
show (Right v) = show v
show (Left (w, Nothing, v) = show w ++ show v
show (Left (w, Just ch, v) = show w ++ show v ++ "caused by" ++ show ch --recursive here
GHC给
Could not deduce (Show b) arising from a use of `show'
from the context (Show a)
bound by the instance declaration at Checked.hs:29:10-35
Possible fix:
add (Show b) to the context of
the data constructor `Checked'
or the instance declaration
In the second argument of `(++)', namely `show ch'
如果我将 (Show b) 添加到实例定义的约束中,GHC 会给出:
Ambiguous constraint `Show b'
At least one of the forall'd type variables mentioned by the constraint
must be reachable from the type after the '=>'
In the instance declaration for `Show (Checked a)'
我应该采取下一步来编译它吗?