Re: Diagnostic bug?

From: Hendrik Tews (tews@tcs.inf.tu-dresden.de)
Date: Tue Jul 27 1999 - 17:34:51 MET DST


Date: Tue, 27 Jul 1999 17:34:51 +0200
Message-Id: <199907271534.RAA15742@ithif20.inf.tu-dresden.de>
From: Hendrik Tews <tews@tcs.inf.tu-dresden.de>
To: caml-list@inria.fr
Subject: Re: Diagnostic bug?
In-Reply-To: <3.0.6.32.19990722165137.00976500@mail.triode.net.au>
 <3.0.6.32.19990722165137.00976500@mail.triode.net.au>

Hi,

as an answer to John I am just telling my heuristics to track
down type errors:

Assuming, that John started with the following program:

    type t = T;;

    let rec g (x) =
      let (aT : t) = f x in ()
    and f x = ();;

then, he gets the error

    File "t.ml", line 5, characters 10-12:
    This expression has type unit but is here used with type t

Now this indicates, that there is something wrong with at least
one of ``f'', ``x'', or ``()''. The error occurs, because from
previous uses of the problematic identifiers the compiler
collected type information, which in incompatible with line 5.
Therefore my strategy is to add type annotations at the first use
of the problematic identifiers, which leads to

    type t = T;;

    let rec g (x) =
      let (aT : t) = (f : 'a -> unit) x in ()
    and f x = ();;

or alternatively

    type t = T;;

    let rec g (x) =
      let (aT : t) = (f x : unit) in ()
    and f x = ();;

For both programs the compiler generates a usable error message.

John Skaller writes:
   
   In my actual code, I got an error
   in a 5000 character expression, and it took three
   days to figure out the error wasn't in that expression
   at all.
   
You are right, error reporting is one of the weak points of the
ocaml system. You can find lots of strange examples in error
reporting. My favorite one is option -i, which prints the types
of top level identifiers, if the file can be compiled. Now, in
the situtation, where the inferred types would be most valuable
--a type error in the file-- the compiler prints just nothing :-(

Bye,

Hendrik



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:23 MET