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 XAA25247 for caml-redistribution; Mon, 2 Jun 1997 23:49:46 +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 XAA25170 for ; Mon, 2 Jun 1997 23:42:00 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.5/8.7.3) with ESMTP id XAA28753; Mon, 2 Jun 1997 23:41:53 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA25165; Mon, 2 Jun 1997 23:41:53 +0200 (MET DST) From: Pierre Weis Message-Id: <199706022141.XAA25165@pauillac.inria.fr> Subject: Re: Instruction return In-Reply-To: <199706021620.JAA20114@blaze.accessone.com> from Dwight VandenBerghe at "Jun 2, 97 09:23:19 am" To: dwight@pentasoft.com (Dwight VandenBerghe) Date: Mon, 2 Jun 1997 23:41:52 +0200 (MET DST) Cc: caml-list@inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis > This is one of the two main control problems with functional programming, > IMHO. > The solution I use is: [...] Dwight's solution uses the a user defined exception Found_it instead of the predefined exception Exit, with a loop or an iteration functional. > The other control problem is when you want the equivalent of: > > x = foo(a); > bar(); > return x; > > If you try > > let x = foo(a) in > bar(); > x > > then bar gets done first, instead of second. That's not true: the language semantics ensures that foo (a) is evaluated before the sequence bar (); x. (This is intuitively evident since the value of x may be required to evaluate the "in" part.) (Try for instance: let foo x = print_string "Hello "; print_string x; x;; let bar () = print_string " world!";; And then # let x = foo ("you") in bar(); x;; Hello you world!- : string = "you") > i use this instead: > > let f x = bar(); x in > in f (foo a) This is provably equivalent, although slightly offuscating. (Theory meets practice in this case, since we get: # let f x = bar(); x in f (foo "you");; Hello you world!- : string = "you") > I haven't found any other serious problems with Caml's logic flow. These > two just take some getting used to. Good. Especially if we discarde the second problem :) Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/