[GHC] #6075: Incorrect interpretation of scoped type variable declaration in GADT pattern match

GHC cvs-ghc at haskell.org
Fri May 4 04:43:07 CEST 2012


#6075: Incorrect interpretation of scoped type variable declaration in GADT
pattern match
------------------------------+---------------------------------------------
 Reporter:  goldfire          |          Owner:                           
     Type:  bug               |         Status:  new                      
 Priority:  normal            |      Component:  Compiler                 
  Version:  7.5               |       Keywords:  ScopedTypeVariables GADTs
       Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple         
  Failure:  None/Unknown      |       Testcase:                           
Blockedby:                    |       Blocking:                           
  Related:                    |  
------------------------------+---------------------------------------------
 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.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/6075>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the Glasgow-haskell-bugs mailing list