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 <[email protected]> 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 > [email protected] > http://www.haskell.org/mailman/listinfo/haskell-cafe _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
