给定以下程序:
{-# LANGUAGE DataKinds, GADTs #-}
{-# LANGUAGE TypeFamilies #-}
data Foo = A | B
type family IsA (foo :: Foo) :: Bool
type instance IsA A = True
type instance IsA B = False
data Bar (foo :: Foo) where
BarA :: (IsA foo ~ True) => Int -> Bar foo
BarB :: (IsA foo ~ False) => String -> Bar foo
f :: Bar A -> Int
f bar = case bar of
BarA x -> x
用于上面定义-fwarn-incomplete-patterns
的总功能时,我从 GHC 7.4.2 收到此警告:f
Warning: Pattern match(es) are non-exhaustive
In a case alternative: Patterns not matched: BarB _
当然,即使尝试添加匹配项也是没有意义的BarB
:
Couldn't match type `'False' with `'True'
Inaccessible code in
a pattern with constructor
BarB :: forall (foo :: Foo). IsA foo ~ 'False => String -> Bar foo,
in a case alternative
In the pattern: BarB _
In a case alternative: BarB _ -> undefined
In the expression:
case bar of {
BarA x -> x
BarB _ -> undefined }
有没有办法说服 GHCf
是完全的?另外,这是 GHC 的一个错误,还是只是一个已知的限制?或者实际上有一个很好的理由为什么没有办法看到模式匹配f
是完整的?