给定一个GADT
由幻像变量索引的索引,我可以使用独立派生来创建一些简单的实例
data Client
data Temporary
data Permanent
data Token ty where
ClientToken :: Token Client
TemporaryToken :: ByteString -> ByteString -> Token Temporary
PermanentToken :: ByteString -> ByteString -> Token Permanent
deriving instance Eq (Token Client)
deriving instance Eq (Token Temporary)
deriving instance Eq (Token Permanent)
这似乎在 GHCi 中完美运行
> ClientToken == ClientToken
True
> TemporaryToken "" "foo" == TemporaryToken "" "bar"
False
但是,当我尝试编译时,会收到警告。
src/Network/HTTP/Conduit/OAuth/Types/Credentials.hs:72:1:
Couldn't match type `Client' with `Temporary'
Inaccessible code in
a pattern with constructor
TemporaryToken :: S8.ByteString
-> S8.ByteString -> Token Temporary,
in an equation for `=='
In the pattern: TemporaryToken a1 a2
In an equation for `==':
== (TemporaryToken a1 a2) (TemporaryToken b1 b2)
= (((a1 == b1)) && ((a2 == b2)))
When typechecking the code for `=='
in a standalone derived instance for `Eq (Token Client)':
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for `Eq (Token Client)'
这似乎是 GADT 派生代码的一个错误位(re: Haskell Inaccessible code bug? and https://ghc.haskell.org/trac/ghc/ticket/8128)但因为它似乎有正确的行为我'我想知道
-fno-warn-*
我可以用一些标志关闭这些警告吗?并且,如果可能的话- 这样做有什么问题的副作用吗?