GADT + Newtype deriving = Erroneous errors

Stefan O'Rear stefanor at cox.net
Tue Mar 27 00:18:34 EDT 2007


This code causes GHC to incorrectly fail - the case *is* reachable.
(I invented this technique in an attempt to directly access the
internal System FC newtype coercion; it promised until a few minutes
ago to solve all the EnumMap performance concerns.)

stefan at stefans:/tmp$ cat A.lhs
> {-# OPTIONS_GHC -fglasgow-exts #-}
>
> data IsIntT x where IsIntT :: IsIntT Int
>
> class IsIntC a where isInt :: IsIntT a
> instance IsIntC Int where isInt = IsIntT
>
> newtype Foo = Foo Int deriving(IsIntC)
>
> x :: IsIntT Foo -> Int
> x IsIntT = (Foo 2) + 2
>
> y = x (isInt :: IsIntT Foo)
stefan at stefans:/tmp$ ghci -v0 A.lhs

A.lhs:11:4:
    Inaccessible case alternative: Can't match types `Foo' and `Int'
    In the pattern: IsIntT
    In the definition of `x': x IsIntT = (Foo 2) + 2

Stefan


More information about the Glasgow-haskell-users mailing list