[GHC] #9605: Misleading error message with forgotten "do"

GHC ghc-devs at haskell.org
Wed Sep 17 22:14:28 UTC 2014


#9605: Misleading error message with forgotten "do"
-------------------------------------+-------------------------------------
       Reporter:  owst               |                   Owner:
           Type:  bug                |                  Status:  new
       Priority:  normal             |               Milestone:
      Component:  Compiler           |                 Version:  7.8.3
       Keywords:                     |        Operating System:
   Architecture:  Unknown/Multiple   |  Unknown/Multiple
     Difficulty:  Unknown            |         Type of failure:
     Blocked By:                     |  None/Unknown
Related Tickets:                     |               Test Case:
                                     |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
 In the following (simplified) code, I forgot to add the do keyword, when
 doing some refactoring. This caused GHC to give a strange error message
 that said approximately
 "The function F is applied to two arguments, but its type T has only
 two"... which is odd!

 {{{#!hs
 import Control.Monad.RWS ( evalRWS, RWS )
 import Control.Monad.Writer.Class ( tell )

 main = print $ evalRWS (go 1) () ()

 go :: Int -> RWS () [String] () ()
 go i = --Oops, forgot a do here
     return (show i) >>= (\l -> tell [l])
     -- go $ i + 1
     go i
 }}}

 Strangely, replacing the "go i" line with the commented-out line above it
 gives a sensible error message, the "Possible cause: `\l -> tell [l]' is
 applied to too many arguments" message, which is correct, and would've
 pointed me straight to the problem.

 The invalid error message, which appears to be the same using GHC 7.6.3
 and 7.8.3, is:

 {{{
 NFA.hs:8:25:
     Couldn't match type ‘String
                          -> Control.Monad.Trans.RWS.Lazy.RWST
                               () [String] ()
 Data.Functor.Identity.Identity ()’
                   with ‘()’
     Expected type: Int
                    -> String
                    -> Control.Monad.Trans.RWS.Lazy.RWST
                         () [String] () Data.Functor.Identity.Identity ()
       Actual type: Int -> ()
     The function ‘\ l -> tell [l]’ is applied to two arguments,
     but its type ‘(Int -> RWS () [String] () ()) -> Int -> ()’
     has only two
     In the second argument of ‘(>>=)’, namely ‘(\ l -> tell [l]) go i’
     In the expression: return (show i) >>= (\ l -> tell [l]) go i
 }}}

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


More information about the ghc-tickets mailing list