Re: Instruction return

From: Pierre Weis (Pierre.Weis@inria.fr)
Date: Mon Jun 02 1997 - 23:41:52 MET DST


From: Pierre Weis <Pierre.Weis@inria.fr>
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)

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



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