From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA32604 for caml-red; Mon, 16 Oct 2000 19:47:54 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA31379 for ; Mon, 16 Oct 2000 18:30:19 +0200 (MET DST) Received: from julie.univ-savoie.fr (univax.univ-savoie.fr [193.48.120.32]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id e9GGUGL29255 for ; Mon, 16 Oct 2000 18:30:16 +0200 (MET DST) Received: from univ-savoie.fr (lama-d134.univ-savoie.fr [193.48.123.134]) by julie.univ-savoie.fr (8.9.3/jtpda-5.3.3) with ESMTP id SAA66081 ; Mon, 16 Oct 2000 18:29:40 +0200 (CEST) Message-ID: <39EB2CF4.DFE8F003@univ-savoie.fr> Date: Mon, 16 Oct 2000 18:29:40 +0200 From: Christophe Raffalli Organization: Laboratoire de =?iso-8859-1?Q?Math=E9matiques?=, =?iso-8859-1?Q?Universit=E9?= de Savoie X-Mailer: Mozilla 4.75 [fr] (X11; U; Linux 2.2.16-9mdksmp i686) X-Accept-Language: fr, en MIME-Version: 1.0 To: Brian Rogoff CC: caml-list@inria.fr Subject: Re: Undefined evaluation order References: Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: weis@pauillac.inria.fr Brian Rogoff a écrit : > > On Mon, 16 Oct 2000, Christophe Raffalli wrote: > > It seems to me that a program making use of evaluation order in function > > or constructor application is wrong ! > > Why? It seems right to me, when you're reading in a file of records or > building an AST from a file, or whatever, to depend on the evaluation > order when building the data structure. I didn't get surprised, because I > know OCaml is right-to-left, but I still find all of that let binding code > redundant, especially when the records get long. There is nothing "wrong" > about it that I can see, except that some people don't like it in concept. > Interestingly, some people really did like it in concept and some of them > were teachers who've witnessed beginners stumble over this very issue. > Ok, I agree for record construction (because of its syntax). But then it should be left to right avaluation order. > > It seems easy to me to add some marking in the type system to detect > > expression with side effects ... > > I thought about this too. Something like Clean's uniqueness types? Maybe > in OCaml 4 :) > > > then one could have a warning (or even > > an error :-) when some code depends on evaluation order and then, in > > this case only, force left to right evaluation order. > > What does this mean? That you would have the programmer manually insert > lets to force the order, or that the compiler does so automatically? > I meant that if the type system detects that the execution depends on the evaluation order then it compiles the code to achieve left to right evaluation order and it also warn the user about it. > > I am sure I would find some bugs in my programs with such a warning -) > > I think the random evaluation order that someone proposed as a test/debugging > tool might be easier than a modification of the type system. > For tricky bug, the probability might be too low to have it appears randomly. However a warning will be always there and gives you a precise line number. I think the extension require just a mark on each arrow which may be ->' (does side effect) -> (does not do side effect ) ->_x|y|z a disjunction of polymorphic variable eg: let compose f g x = f (g x) would have type compose : ('b ->_x 'c) -> ('a ->_y 'b) -> 'a ->_x|y 'c meaning that compose f g x does a side effect when receiving its third argument if f or g does a side effect when receiving their first argument. I guess that it is does not need to much work to come up with a correct type system infering such types (I may be wrong ... ). And knowing if an expression has side effects could be usefull for the compiler in other cases ? -- Christophe Raffalli Université de Savoie Batiment Le Chablais, bureau 21 73376 Le Bourget-du-Lac Cedex tél: (33) 4 79 75 81 03 fax: (33) 4 79 75 87 42 mail: Christophe.Raffalli@univ-savoie.fr www: http://www.lama.univ-savoie.fr/~RAFFALLI