我有一个 GADT,它只与两个不同的参数 ForwardPossible 和 () 一起使用:
-- | Used when a forward definition is possible.
data ForwardPossible = ForwardPossible deriving (Eq, Ord, Typeable, Data, Show)
-- | GADT which accepts forward definitions if parameter is ForwardPossible.
data OrForward t forward where
OFKnown :: t -> OrForward t forward
OFForward :: NamespaceID -> SrcSpan -> BS.ByteString -> OrForward t ForwardPossible
deriving instance Eq t => Eq (OrForward t forward)
deriving instance Ord t => Ord (OrForward t forward)
deriving instance Typeable2 OrForward
deriving instance Show t => Show (OrForward t forward)
我想派生足够的 Data.Data 实例来涵盖 OrForward t () 和 OrForward t ForwardPossible。我认为一般 (Data t, Data forward) => OrForward t forward 实例是不可能的,除非它普遍忽略 OFForward,但是 Data t => OrForward t ForwardPossible 和 (Data t, Data forward) => 的重叠实例如果有办法让 ghc 派生这些实例,OrForward t 前向实例可能是一个解决方案。
我试过定义:
deriving instance Data t => Data (OrForward t ())
deriving instance Data t => Data (OrForward t ForwardPossible)
但随后 ghc 给了我一个这样的错误:
Duplicate type signature:
Structure.hs:53:1-70: $tOrForward :: DataType
Structure.hs:52:1-49: $tOrForward :: DataType