Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: Warnings in ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pierre Weis <Pierre.Weis@i...>
Subject: Re: Warnings in ocaml
> * 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 kurims.kyoto-u.ac.jp
> 		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>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, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/