Re: Diagnostic bug?

From: Hendrik Tews (
Date: Tue Jul 27 1999 - 17:34:51 MET DST

Date: Tue, 27 Jul 1999 17:34:51 +0200
Message-Id: <>
From: Hendrik Tews <>
Subject: Re: Diagnostic bug?
In-Reply-To: <>


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 "", 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 :-(



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