[GHC] #1901: 6.8.1 incorrectly infers contexts from pattern matches.

GHC trac at galois.com
Thu Nov 15 10:16:56 EST 2007


#1901: 6.8.1 incorrectly infers contexts from pattern matches.
----------------------+-----------------------------------------------------
 Reporter:  guest     |          Owner:         
     Type:  bug       |         Status:  new    
 Priority:  normal    |      Milestone:         
Component:  Compiler  |        Version:  6.8.1  
 Severity:  normal    |       Keywords:         
 Testcase:            |   Architecture:  Unknown
       Os:  Unknown   |  
----------------------+-----------------------------------------------------
 The following code is rejected by GHC 6.6.1

 {{{

 data Foo a = (Num a) => MkFoo a

 data (Num a) =>  Foo' a =  MkFoo' a

 data Foo'' a =
     (Num a) => X a
   | (Show a) => Y a

 fun :: Foo'' t -> String
 fun (Y a) = show a

 -- Prelude> :load "/Users/jules/personal/progs/test.hs"
 -- [1 of 1] Compiling Main             (
 /Users/jules/personal/progs/test.hs, interpreted )

 -- /Users/jules/personal/progs/test.hs:10:12:
 --     No instance for (Show t)
 --       arising from use of `show'
 --       at /Users/jules/personal/progs/test.hs:10:12-17
 --     Possible fix: add (Show t) to the type signature(s) for `fun'
 --     In the expression: show a
 --     In the definition of `fun': fun (Y a) = show a
 -- Failed, modules loaded: none.

 }}}

 According to the GHC manual (section 8.4.5) this rejection is correct.
 That is, haskell98 is not supposed to infer contexts from a pattern match.
 However strange that behaviour is, it is apparently the standard.

 6.8.1 appears to do the more natural, but incorrect, thing, and accept
 this program.

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


More information about the Glasgow-haskell-bugs mailing list