次のプログラムがあるとします。
{-# 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
た関数全体に使用すると、GHC7.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 }
f
合計であるGHCを説得する方法はありますか?また、これはGHCのバグですか、それとも既知の制限ですか。f
または、パターンの一致が完全であることを確認する方法がないという非常に正当な理由が実際にありますか?