Incorrect interpretation of scoped type variable declaration in GADT pattern match
Consider the following code:
{-# LANGUAGE GADTs, FlexibleInstances, ScopedTypeVariables #-}
class FromThinAir a where
create :: a
instance FromThinAir Int where
create = 42
instance FromThinAir [Char] where
create = "Poof!"
data GADT a where
GInt :: GADT Int
GArrow :: (FromThinAir a, Show a) => GADT (a -> b)
data NotGADT where
NInt :: Int -> NotGADT
NArrow :: (FromThinAir a, Show a) => (a -> b) -> NotGADT
dumb :: NotGADT -> String
dumb g = case g of
NInt _ -> show (create :: Int)
NArrow (f :: (a -> b)) -> show (create :: a)
dumber :: GADT a -> String
dumber g = case g of
GInt -> show (create :: Int)
(GArrow :: GADT (a -> b)) -> show (create :: a)
The function dumb
compiles just fine. The function dumber
does not. The problem appears to be that GHC interprets the type signature on GArrow
as a type signature that applies to all cases, or (equivalently) applies to g
. In dumb
, however, the type signature is applied to a variable, not the constructor, and GHC does the right thing.
Note that the FromThinAir
class simply sets the stage for the bug. I don't believe it's an integral part of it all.
This was tested on 7.5.20120426.
Trac metadata
Trac field | Value |
---|---|
Version | 7.5 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |