假设我有以下代码:
{-# LANGUAGE GADTs, DeriveDataTypeable, StandaloneDeriving #-}
import Data.Typeable
class Eq t => OnlyEq t
class (Eq t, Typeable t) => BothEqAndTypeable t
data Wrapper a where
Wrap :: BothEqAndTypeable a => a -> Wrapper a
deriving instance Eq (Wrapper a)
deriving instance Typeable1 Wrapper
Run Code Online (Sandbox Code Playgroud)
然后,以下实例声明工作,没有约束t:
instance OnlyEq (Wrapper t)
Run Code Online (Sandbox Code Playgroud)
并做我期望它做的事情.
但是以下实例声明不起作用:
instance BothEqAndTypeable (Wrapper t)
Run Code Online (Sandbox Code Playgroud)
自GHC - 我使用7.6.1 - 抱怨说:
No instance for (Typeable t)
arising from the superclasses of an instance declaration
Possible fix: …Run Code Online (Sandbox Code Playgroud) 我有一个只用过两个不同参数的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 …Run Code Online (Sandbox Code Playgroud)