Re: Warnings in ocaml

From: Pierre Weis (
Date: Fri Feb 19 1999 - 19:32:46 MET

From: Pierre Weis <>
Message-Id: <>
Subject: Re: Warnings in ocaml
To: (Jacques GARRIGUE)
Date: Fri, 19 Feb 1999 19:32:46 +0100 (MET)
In-Reply-To: <> from "Jacques GARRIGUE" at Feb 19, 99 09:30:15 pm

> * having a warning when a function doesn't return unit in a sequence
> may catch some bugs, but this is a pain with imperative programming
> style, where you may not be interested by the result of a function but
> just by its side-effects.

Could you please give me some interesting examples (Yes, I know you
can write this kind of functions, but I would like some examples where
it seems really painful to work it out otherwise).

Furthermore the point here is that this warning is useful, since we
had 2 undetected bugs into the Objective Caml system due to the lack
of this warning.

> Of course you can switch off the warning,
> but I'm not sure having it on is a good default, since the default
> mode should be normative.

The Caml system example shows that this warning is useful, even for
the most experienced programmers, let alone the beginners that do not
know how to get the warning on if they know that it exists...

> ex. wrong code
> x = 3; ...
> ^ should be <-

Or even x := 3.

> ex. right code
> f x y; ...
> where f: t1 -> t2 -> int has some interesting side-effect.

In this case the warning tells you that you may be have a further look
to your f function: is it necessary to mix side effects and purely
functional computation ? Very often, this is not necessary and
rewriting the code to avoid the mixing gets it clearer. If it is not
the case, you can tell it to the reader and write

let _ = f x y in

> * another common error with imperative code is partial application in
> a toplevel call inside a module
> let _ =
> somefunc hsj hjfhfd
> somefunc takes 3 arguments but is only given 2. Since this is a
> let-definition no warning is printed while such a partial application
> is pretty meaningless.
> Regards,
> Jacques
> ---------------------------------------------------------------------------
> Jacques Garrigue Kyoto University garrigue at
> <A HREF=>JG</A>

So you want another warning for dummy definitions at the toplevel of
modules when the application if partial ? Or may be you want to extend
the sequence warning to this case when the result is not unit ?

Best regards,

Pierre Weis

INRIA, Projet Cristal,,

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