caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: Warnings in ocaml
@ 1999-02-22 17:25 Don Syme
  1999-02-22 18:16 ` Pierre Weis
  0 siblings, 1 reply; 12+ messages in thread
From: Don Syme @ 1999-02-22 17:25 UTC (permalink / raw)
  To: caml-list


> Also it will be useful to produce warning when polymorphic comparison
> occurs.

Here's another problem: I wrote about 20,000 lines where I used the built in
equality for
a particular type (that represented terms in a theorem prover).  Now I want
to implement
my own equality function on the type, and never user built-in equality.  I
can see 
Ocaml has generally made the right choice in not having
equality types like SML, but in this situation some sort of annotation +
warning would
be incredibly useful, since as it stands the Ocaml type system doesn't help
me find all those horrible
uses of built-in equality that I coded into my program, when you really feel
like it should...

Don

------------------------------------------------------------------------
At the lab:                                     At home:
Microsoft Research Cambridge                    11 John St
St George House                                 CB1 1DT
Cambridge, CB2 3NH, UK
Ph: +44 (0) 1223 744797                         Ph: +44 (0) 1223 722244
http://research.microsoft.com/users/dsyme
email: dsyme@microsoft.com
------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: Warnings in ocaml
@ 1999-02-22 14:56 Andrew Kay
  0 siblings, 0 replies; 12+ messages in thread
From: Andrew Kay @ 1999-02-22 14:56 UTC (permalink / raw)
  To: caml-list


> eg      let _ = List.map f
>         in print_endline "done map..."
>  
> Are there any plans to provide a warning for this in ocaml?  
 
To save anyone else the bother, I'll point out the error of
my ways myself.  

I think SML has (had?) a check which stopped you accidentally
ignoring a function value before a semi-colon.  However, since
functions are first class citizens, why shouldn't you want to ignore
them just as you might ignore a list or integer value?

So instead, I propose you write an explicit ignore function for each
type you want to ignore:

val ignore_int : int -> unit
val ignore_fred : fred -> unit
...

Andrew Kay
Sharp Labs Europe Ltd, Oxford Science Park, Oxford, UK, OX4 4GA
Andrew.Kay@sharp.co.uk  Tel:+44 1865 747711 FAX:+44 1865 747717




^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: Warnings in ocaml
@ 1999-02-22 13:45 Andrew Kay
  0 siblings, 0 replies; 12+ messages in thread
From: Andrew Kay @ 1999-02-22 13:45 UTC (permalink / raw)
  To: caml-list

Frank A. Christoph wrote:
> I copied from SML and defined a procedure "ignore":
> so now I would write:
>   ignore (f x y); ...

Yes, we did this too.  This certainly gets rid of the warning about
the type to the left of ";", but it doesn't address the problem of
accidentally using a partially applied function.

eg      let _ = List.map f
	in print_endline "done map..."

Are there any plans to provide a warning for this in ocaml?  

Andrew Kay
Sharp Labs Europe Ltd, Oxford Science Park, Oxford, UK, OX4 4GA
Andrew.Kay@sharp.co.uk  Tel:+44 1865 747711 FAX:+44 1865 747717




^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: Warnings in ocaml
@ 1999-02-22  9:55 Frank A. Christoph
  1999-02-22 12:36 ` Xavier Leroy
  1999-02-22 18:33 ` Ching-Tsun Chou
  0 siblings, 2 replies; 12+ messages in thread
From: Frank A. Christoph @ 1999-02-22  9:55 UTC (permalink / raw)
  To: caml-list

 Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp> wrote:
>I have a few comments about new 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. 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.
>
>ex. wrong code
> x = 3; ...
>   ^ should be <-
>
>ex. right code
> f x y; ...
>where f: t1 -> t2 -> int has some interesting side-effect.

I copied from SML and defined a procedure "ignore":

  let ignore k =
    let _ = k in ()

so now I would write:

  ignore (f x y); ...

I agree that it can be a pain to be explicit about this sometimes, but "ignore" makes it fairly transparent.

BTW, this procedure is a good candidate for addition to the standard library.

--FC


^ permalink raw reply	[flat|nested] 12+ messages in thread
* Warnings in ocaml
@ 1999-02-19 12:30 Jacques GARRIGUE
  1999-02-19 18:32 ` Pierre Weis
  0 siblings, 1 reply; 12+ messages in thread
From: Jacques GARRIGUE @ 1999-02-19 12:30 UTC (permalink / raw)
  To: caml-list

I have a few comments about new 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. 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.

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

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

* 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>




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1999-02-23 14:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-22 17:25 Warnings in ocaml Don Syme
1999-02-22 18:16 ` Pierre Weis
  -- strict thread matches above, loose matches on Subject: below --
1999-02-22 14:56 Andrew Kay
1999-02-22 13:45 Andrew Kay
1999-02-22  9:55 Frank A. Christoph
1999-02-22 12:36 ` Xavier Leroy
1999-02-22 13:24   ` Anton Moscal
1999-02-22 15:06   ` Michael Hicks
1999-02-22 18:33 ` Ching-Tsun Chou
1999-02-19 12:30 Jacques GARRIGUE
1999-02-19 18:32 ` Pierre Weis
1999-02-20 10:45   ` Markus Mottl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).