id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc,os,architecture,failure,difficulty,testcase,blockedby,blocking,related
6075,Incorrect interpretation of scoped type variable declaration in GADT pattern match,goldfire,,"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.",bug,closed,normal,,Compiler,7.5,invalid,ScopedTypeVariables GADTs,,Unknown/Multiple,Unknown/Multiple,None/Unknown,Unknown,,,,
