[GHC] #9173: Better type error messages

GHC ghc-devs at haskell.org
Mon Jun 5 13:00:03 UTC 2017


#9173: Better type error messages
-------------------------------------+-------------------------------------
        Reporter:  simonpj           |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.8.2
      Resolution:                    |             Keywords:
                                     |  TypeErrorMessages
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Incorrect         |  Unknown/Multiple
  warning at compile-time            |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by vanto):

 Replying to [[span(style=color: #FF0000, simonpj )]]\\

 Hello simonpj,\\
 I agree with rwbarton.
 But instead of using the word "context" I prefer the use of the word
 "signature".\\
 A signature is a description of each component of a definition of a
 function,
 or in a more general way by talking about an expression.\\
 A Type signature defined by the programmer takes precedence over the Type
 of the result of the calculated function.\\
 We could write :

 {{{Type `Int` expected by signature}}}.\\

 or this sentence that is simple and sounds well\\

 {{{
 The Type of the result is not in accordance with the Type of the signature
 }}}
 Or with the Type write inside\\

 {{{
 The Type `[Char]` of the result is not in accordance with the Type `Int`
 of the signature
 }}}
 The word "context" is quite different.\\
 It implies a greater scope in the code.
 It would be the equivalent of a set.\\
 But one thing must be noted.\\
 This thing is not to write the signature of the function.\\
 If I write\\

 {{{
 module Foo where
     addThree = \x -> x + 3
     y = addThree $ Just 5
 }}}
 GHCi sayd\\

 {{{
 Prelude> :l foo.hs
 [1 of 1] Compiling Foo              ( foo.hs, interpreted )

 foo.hs:2:22: error:
     * No instance for (Num (Maybe a0)) arising from a use of `+'
     * In the expression: x + 3
       In the expression: \ x -> x + 3
       In an equation for `addThree': addThree = \ x -> x + 3

 foo.hs:3:25: error:
     * Ambiguous type variable `a0' arising from the literal `5'
       prevents the constraint `(Num a0)' from being solved.
       Relevant bindings include y :: Maybe a0 (bound at foo.hs:3:5)
       Probable fix: use a type annotation to specify what `a0' should be.
       These potential instances exist:
         instance Num Integer -- Defined in `GHC.Num'
         instance Num Double -- Defined in `GHC.Float'
         instance Num Float -- Defined in `GHC.Float'
         ...plus two others
         (use -fprint-potential-instances to see them all)
     * In the first argument of `Just', namely `5'
       In the second argument of `($)', namely `Just 5'
       In the expression: addThree $ Just 5
 Failed, modules loaded: none.
 Prelude>
 }}}
 Here there is no Type signature in the context.\\
 The sentence {{{* No instance for (Num (Maybe a0)) arising from a use of
 `+'}}} is
 more explicit.\\
 I hope this will help.

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


More information about the ghc-tickets mailing list