[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 1997-06-02 (21:49) |
From: | Pierre Weis <Pierre.Weis@i...> |
Subject: | Re: Instruction return |
> 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/