From: Pierre Weis <Pierre.Weis@inria.fr>
To: dwight@pentasoft.com (Dwight VandenBerghe)
Cc: caml-list@inria.fr
Subject: Re: Instruction return
Date: Mon, 2 Jun 1997 23:41:52 +0200 (MET DST) [thread overview]
Message-ID: <199706022141.XAA25165@pauillac.inria.fr> (raw)
In-Reply-To: <199706021620.JAA20114@blaze.accessone.com> from Dwight VandenBerghe at "Jun 2, 97 09:23:19 am"
> 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/
next prev parent reply other threads:[~1997-06-02 21:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-06-02 16:23 Dwight VandenBerghe
1997-06-02 21:41 ` Pierre Weis [this message]
-- strict thread matches above, loose matches on Subject: below --
1997-05-31 17:30 Pascal Zimmer
1997-06-02 14:15 ` Pierre Weis
1997-06-03 8:37 ` Vincent Poirriez
1997-06-03 10:24 ` Pierre Weis
1997-06-03 14:17 ` Vincent Poirriez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199706022141.XAA25165@pauillac.inria.fr \
--to=pierre.weis@inria.fr \
--cc=caml-list@inria.fr \
--cc=dwight@pentasoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox