COMPLETE sets don't get type-checked
GHC does a bad job at checking whether the ConLike
s of a COMPLETE
set can actually appear in the same pattern match. Example:
{-# LANGUAGE PatternSynonyms #-}
module Lib where
pattern A :: Maybe Bool
pattern A <- _
pattern B :: Maybe ()
pattern B <- _
{-# COMPLETE A, B #-}
This compiles just fine, whereas I had at least expected a warning. Strange enough the program gets rejected when you remove the Maybe
type constructor, so it seems there is some machinery in place which is just not robust enough.
My understanding of a proper fix would try to find a unifying type of all return types. So, starting with a
, we want to gradually refine it to Maybe b
, then get to know that b ~ Bool
, then b ~ ()
and reject. This would still allow
{-# LANGUAGE PatternSynonyms #-}
module Lib where
pattern A :: Either Bool b
pattern A <- _
pattern B :: Either a ()
pattern B <- _
{-# COMPLETE A, B #-}
f :: Either Bool () -> ()
f A = ()
f B = ()
by inferring the most general unifying type Either Bool ()
for the COMPLETE
pragma.