[GHC] #12106: Wrong type inferenced for locally defined function

GHC ghc-devs at haskell.org
Mon May 23 19:25:46 UTC 2016


#12106: Wrong type inferenced for locally defined function
-------------------------------------+-------------------------------------
           Reporter:  syd            |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.0.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Consider the following example.

 {{{#!hs
 data A = A
     deriving Show
 data B = B
     -- deriving Show is missing here.

 main :: IO ()
 main = do
     let myPrint = putStrLn . show
     myPrint A
     myPrint B
 }}}

 The {{{Show}}} instance for {{{B}}} is missing and the most general type
 for {{{myPrint}}} is {{{Show a => a -> IO ()}}}.

 Ghc, however, reports the following error:

 {{{
 file.hs:10:13: error:
     • Couldn't match expected type ‘A’ with actual type ‘B’
     • In the first argument of ‘myPrint’, namely ‘B’
       In a stmt of a 'do' block: myPrint B
       In the expression:
         do { let myPrint = putStrLn . show;
              myPrint A;
              myPrint B }
 }}}

 This error won't help the programmer find the missing {{{deriving Show}}}
 declaration. Instead, the error should read something like {{{No instance
 for (Show B) arising from a use of ‘myPrint’}}}.

 Weirdly, when I type this {{{main}}} function into ghci, the error is
 'correct'.

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


More information about the ghc-tickets mailing list