[GHC] #12864: Produce type errors after looking at whole applications

GHC ghc-devs at haskell.org
Mon Nov 21 20:53:33 UTC 2016


#12864: Produce type errors after looking at whole applications
-------------------------------------+-------------------------------------
        Reporter:  nomeata           |                Owner:
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler (Type    |              Version:  8.0.1
  checker)                           |
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Poor/confusing    |  Unknown/Multiple
  error message                      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by nomeata):

 Here are a few examples with proposed alternative error messages:

 {{{#!hs
 module ErrorMessages where

 i1, i2, i3 :: Int
 i1 = 0
 i2 = 0
 i3 = 0

 d1 :: Double
 d1 = 1


 fid :: Int -> Double -> Int
 fid = undefined

 fii :: Int -> Int -> Int
 fii = undefined

 fidi :: Int -> Double -> Int -> Int
 fidi = undefined


 ex1 :: Int
 ex1 = fid i1 i2

 {-
 ErrorMessages.hs:17:14: error:
     • Couldn't match expected type ‘Double’ with actual type ‘Int’
     • In the second argument of ‘fid’, namely ‘i2’
       In the expression: fid i1 i2
       In an equation for ‘ex1’: ex1 = fid i1 i2

 So far ok
 -}

 ex2 :: Int
 ex2 = fid d1 i1

 {-
 ErrorMessages.hs:36:11: error:
     • Couldn't match expected type ‘Int’ with actual type ‘Double’
     • In the first argument of ‘fid’, namely ‘d1’
       In the expression: fid d1 i1
       In an equation for ‘ex2’: ex2 = fid d1 i1

 ErrorMessages.hs:36:14: error:
     • Couldn't match expected type ‘Double’ with actual type ‘Int’
     • In the second argument of ‘fid’, namely ‘i1’
       In the expression: fid d1 i1
       In an equation for ‘ex2’: ex2 = fid d1 i1

 Two error messages for one simple error! Why not

 ErrorMessages.hs:36:7: error:
     • Cannot use expression ‘fid’ of type ‘Double -> Int -> Int’
       as a function of type ‘Int -> Double -> Int’
     • Probable cause: The first and second argument are swapped
       In the expression: fid d1 i1
       In an equation for ‘ex2’: ex2 = fid d1 i1
 -}

 ex3 :: Int
 ex3 = fidi i1 i2

 {-
 ErrorMessages.hs:20:7: error:
     • Couldn't match expected type ‘Int’ with actual type ‘Int -> Int’
     • Probable cause: ‘fidi’ is applied to too few arguments
       In the expression: fidi i1 i2
       In an equation for ‘ex3’: ex3 = fidi i1 i2

 ErrorMessages.hs:20:15: error:
     • Couldn't match expected type ‘Double’ with actual type ‘Int’
     • In the second argument of ‘fidi’, namely ‘i2’
       In the expression: fidi i1 i2
       In an equation for ‘ex3’: ex3 = fidi i1 i2

 Bad; two errors for one. Why not:

 ErrorMessages.hs:20:15: error:
     • Missing second argument to ‘fidi’ of type ‘Double’
     • In the function application: fidi i1 i2
       In an equation for ‘ex3’: ex3 = fidi i1 i2
 -}

 ex4 :: Int
 ex4 = fii i1 succ i2

 {-
 ErrorMessages.hs:57:7: error:
     • Couldn't match expected type ‘Int -> Int’ with actual type ‘Int’
     • The function ‘fii’ is applied to three arguments,
       but its type ‘Int -> Int -> Int’ has only two
       In the expression: fii i1 succ i2
       In an equation for ‘ex4’: ex4 = fii i1 succ i2

 ErrorMessages.hs:57:14: error:
     • Couldn't match expected type ‘Int’ with actual type ‘a0 -> a0’
     • Probable cause: ‘succ’ is applied to too few arguments
       In the second argument of ‘fii’, namely ‘succ’
       In the expression: fii i1 succ i2
       In an equation for ‘ex4’: ex4 = fii i1 succ i2

 Bad; again two errors for one. Why not:

 ErrorMessages.hs:20:15: error:
     • Cannot use expression ‘fii’ of type ‘Int -> Int -> Int’
       as a function of type ‘Int -> (Int -> Int) -> Int -> Int’
     • Probable cause: Missing parenthesis around ‘succ i2’
     • In the function application: fii i1 succ i2
       In an equation for ‘ex4’: ex4 = fii i1 succ i2
 -}
 }}}

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


More information about the ghc-tickets mailing list