Opened 9 years ago

Closed 3 years ago

#956 closed feature request (fixed)

improving error messages #1

Reported by: Bulat Ziganshin <Bulat.Ziganshin@…> Owned by: simonpj
Priority: normal Milestone:
Component: Compiler Version: 6.6
Keywords: Cc: merehap@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):


the following program

main = do putChar 'a'

makes this error message::

    Couldn't match expected type `IO' against inferred type `(->) Char'
    Probable cause: `putChar' is applied to too few arguments
    In the expression: putChar

while the 'probable cause' is very helpful, the error message by itself is hard to understand for novices. i propose in these cases to work against known value types. in this case, we know that 'putChar' has type 'Char -> IO ()' and GHC may report smth like this:

'putChar': expression of type 'Char -> IO ()' used in context that
requires expression of 'IO ()' type
Probably, you've omitted parameter of type 'Char' to this expression

comparing this with existing message shows that may be improved:

1) for me, it's still hard to understand what is "expected" and "inferred" means. i guess that for true beginners it's even harder. i prefer to see something more English and less Mathematic - it will be very helpful

2) instead of obscure 'IO' and `(->) Char' types, i strongly prefer to see more pragmatic 'IO ()' and 'Char -> IO ()' ones

3) 'Probable cause' may be more pleasant by telling position and type of skipped argument(s)

my second example is almost the same :)

main = do putChar
          putChar 'a'

in this case error message is even worser:

    Couldn't match expected type `(->) Char' against inferred type `IO'
    Probable cause: `putChar' is applied to too many arguments
    In the expression: putChar 'a'

afaiu, here GHC thought that putChar should have 'IO ()' type. or, it may think that operations in this monad has type 'Char -> IO ()'. anyway, it will be great if GHC will know that operations in monad usually has type 'IO a' or 'm a' and try to use this heuristic when dealing with such errors (different types of statements in 'do' block)

Change History (8)

comment:1 Changed 9 years ago by igloo

  • Milestone set to 6.6.1
  • Priority changed from normal to low

comment:2 Changed 9 years ago by simonmar

  • Milestone changed from 6.6.1 to 6.8
  • Owner set to simonpj
  • Priority changed from low to normal

comment:3 Changed 8 years ago by simonpj

  • Milestone changed from 6.8 branch to _|_

See also #451

comment:4 Changed 7 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:5 Changed 7 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple

comment:6 Changed 5 years ago by merehap

  • Cc merehap@… added
  • Type of failure set to None/Unknown

comment:7 Changed 3 years ago by morabbin

Given that GHC 7's error messages are generally more informative, and in these cases produce very friendly messages:

    Couldn't match expected type `IO b0'
                with actual type `Char -> IO ()'
    In a stmt of a 'do' block: putChar
    In the expression:
      do { putChar 'a';
           putChar }
    In an equation for `main':
          = do { putChar 'a';
                 putChar }

perhaps this ought to be closed as fixed. The message doesn't suggest a probable cause or fix, but I think that's fine here.

comment:8 Changed 3 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.