[Haskell-cafe] Spurious pattern match warnings with GADTs

Erik Hesselink hesselink at gmail.com
Thu Jan 12 22:22:44 CET 2012


Type classes are open, so nothing prevents someone from adding an
instance 'C0 T1' and calling 't' with constructor 'B', causing a crash
due to the missing pattern.

Erik

On Thu, Jan 12, 2012 at 21:40, Tom Hawkins <tomahawkins at gmail.com> wrote:
> Let's say I have:
>
> data T0
> data T1
>
> data T a where
>  A :: T T0
>  B :: T T1
>
> Then I can write the following without getting any non-exhaustive
> pattern match warnings:
>
> t :: T T0 -> String
> t a = case a of
>  A -> "A"
>
> However, if I use type classes to constrain the constructors, instead
> of using the phantom types directly:
>
> class C0 a
> instance C0 T0
>
> class C1 a
> instance C1 T1
>
> data T a where
>  A :: C0 a => T a
>  B :: C1 a => T a
>
> Then I get a non-exhaustive pattern match warning on 't'.  How come?
> (I'm using GHC 7.0.4)
>
> It appears that the intelligent pattern analysis of the first example
> is a relatively recent addition [1].
>
> -Tom
>
> [1] http://hackage.haskell.org/trac/ghc/ticket/3476
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list