[GHC] #6074: Instance inference failure with GADTs

GHC cvs-ghc at haskell.org
Fri May 4 04:21:49 CEST 2012


#6074: Instance inference failure with GADTs
------------------------------+---------------------------------------------
 Reporter:  goldfire          |          Owner:                  
     Type:  bug               |         Status:  new             
 Priority:  normal            |      Component:  Compiler        
  Version:  7.5               |       Keywords:  GADTs           
       Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
  Failure:  None/Unknown      |       Testcase:                  
Blockedby:                    |       Blocking:                  
  Related:                    |  
------------------------------+---------------------------------------------
 Consider the following code:

 {{{
 {-# LANGUAGE GADTs, FlexibleInstances #-}

 class Stringable a where
   toString :: a -> String

 data GADT a where
   GInt :: GADT Int
   GBool :: GADT Bool

 instance Stringable (GADT Int) where
   toString _ = "constructor GInt"
 instance Stringable (GADT Bool) where
   toString _ = "constructor GBool"

 mkString :: GADT a -> String
 mkString g = toString g

 mkString' :: GADT a -> String
 mkString' g = case g of
   GInt  -> toString g
   GBool -> toString g
 }}}

 The function {{{mkString}}} does not compile, while the function
 {{{mkString'}}} does. The problem seems to be that there is no instance
 declaration for {{{GADT a}}}, although there are instances for all the
 possible instantiations of {{{a}}}. It seems that requiring a {{{case}}}
 statement where all patterns are accounted for and all branches contain
 the same expression should be unnecessary.

 This was tested on 7.5.20120426.

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



More information about the Glasgow-haskell-bugs mailing list