<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/10/5ad948ee2283f3ece3b1bc3cf4238ccb"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-21T20:27:09"
  subject="Re: [Caml-list] OCaml wishlist"
  prev="2003/10/7497ee1b70d6745da11d738b9572fbe3"
  next="2003/10/528446ab0441688dd60d9d0c2ad9a9d3"
  prev-in-thread="2003/10/7497ee1b70d6745da11d738b9572fbe3"
  next-in-thread="2003/10/528446ab0441688dd60d9d0c2ad9a9d3"
  prev-thread="2003/10/486acf652571889eddb2bd9834f62d74"
  next-thread="2003/10/36ad1eb7cafe994a34e3761a559f87ee"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] OCaml wishlist">
<msg 
  url="2003/10/08bd0ecfdca5cc2e49c8e01b5c9d4507"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-10-21T14:29:23"
  subject="[Caml-list] OCaml wishlist">
<msg 
  url="2003/10/cb6d61f43e94f4bec873d3522da4dfad"
  from="Michal Moskal &lt;malekith@p...&gt;"
  author="Michal Moskal"
  date="2003-10-21T15:00:19"
  subject="Re: [Caml-list] OCaml wishlist">
<msg 
  url="2003/10/5dd71e02247c880498f410c239374234"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-10-21T17:17:16"
  subject="Re: [Caml-list] OCaml wishlist">
</msg>
<msg 
  url="2003/10/2452fac51ab932ac2bd176e8183a524f"
  from="William Lovas &lt;wlovas@s...&gt;"
  author="William Lovas"
  date="2003-10-21T19:01:56"
  subject="Re: [Caml-list] OCaml wishlist">
<msg 
  url="2003/10/a1b78b7694f2d67a6e6b7db51de25f98"
  from="Alain.Frisch@e..."
  author="Alain.Frisch@e..."
  date="2003-10-21T19:46:45"
  subject="Re: [Caml-list] OCaml wishlist">
</msg>
<msg 
  url="2003/10/7497ee1b70d6745da11d738b9572fbe3"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-10-21T19:54:09"
  subject="Re: [Caml-list] OCaml wishlist">
<msg 
  url="2003/10/5ad948ee2283f3ece3b1bc3cf4238ccb"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-21T20:27:09"
  subject="Re: [Caml-list] OCaml wishlist">
</msg>
<msg 
  url="2003/10/528446ab0441688dd60d9d0c2ad9a9d3"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-21T20:53:04"
  subject="Re: [Caml-list] OCaml wishlist">
<msg 
  url="2003/10/f4aa63fac624d2412ec939b942d8eb7d"
  from="Alain.Frisch@e..."
  author="Alain.Frisch@e..."
  date="2003-10-21T21:46:42"
  subject="Re: [Caml-list] OCaml wishlist">
</msg>
</msg>
<msg 
  url="2003/10/a24e55f813003425848ab701e4e4741d"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-10-22T00:59:50"
  subject="Re: [Caml-list] OCaml wishlist">
<msg 
  url="2003/10/0387387ca1566a60c7eb714103fcafca"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-10-22T02:52:43"
  subject="Re: [Caml-list] OCaml wishlist">
<msg 
  url="2003/10/e051e894779e1d750dc514438ac003da"
  from="Michal Moskal &lt;malekith@p...&gt;"
  author="Michal Moskal"
  date="2003-10-22T15:30:15"
  subject="Re: [Caml-list] OCaml wishlist">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/10/fe6b3048ed9db4da74f54d088173989d"
  from="David Brown &lt;caml-list@d...&gt;"
  author="David Brown"
  date="2003-10-21T19:08:05"
  subject="Re: [Caml-list] OCaml wishlist">
</msg>
<msg 
  url="2003/10/23b761709f504ab6af2a1f09d8d07c5a"
  from="Alain.Frisch@e..."
  author="Alain.Frisch@e..."
  date="2003-10-21T19:18:33"
  subject="Re: [Caml-list] OCaml wishlist">
</msg>
</msg>
</thread>

<contents>
Here's a simple way of approximating what you want.  It's ugly, but camlp4
could be used for providing the appropriate syntactic sugar, I imagine.

exception Return

let rval = ref None in
try


with
  Return -&gt;
     match !rval with





&gt; On Tue, Oct 21, 2003 at 01:28:13PM -0400, William Lovas wrote:
&gt;&gt; What you want is a return *statement*, but such a beast is incompatible
&gt;&gt; with O'Caml, since O'Caml is an expression-oriented language.  I don't
&gt;&gt; see
&gt;&gt; an easy way of making a `return' expression that behaves the way you
&gt;&gt; want
&gt;&gt; it to.
&gt;
&gt; Perhaps there's a misunderstanding here. I don't want to change the
&gt; expression-oriented nature of the language. The 'return' would and
&gt; must return the same type as the rest of the code.
&gt;
&gt;&gt; Better, though, in my opinion, would be to adapt your
&gt;&gt; mental syntax to fit the functional style than to adapt the functional
&gt;&gt; language to cater to your imperative style.
&gt;
&gt; I'm really looking for help on this! My working theory at the moment
&gt; though is that writing UIs involves writing essentially imperative
&gt; code. One small example from some real code:
&gt;
&gt;   let quit _ =
&gt;     if !test_id = 0 then (
&gt;       GMain.Main.quit (); false
&gt;     ) else (
&gt;       let icon = GMisc.image () in
&gt;       icon#set_stock `DIALOG_QUESTION;
&gt;       icon#set_icon_size `DIALOG;
&gt;       let buttons = [ "Quit"; "Cancel" ] in
&gt;       let ans = GToolbox.question_box ~title:"Quit" ~icon ~buttons
&gt;           ("Are you sure you want to quit? This may lose any\n" ^
&gt;            "results from this assessment.") in
&gt;       if ans = 1 then (
&gt;         GMain.Main.quit (); false       (* User requested quit. *)
&gt;        )
&gt;       else
&gt;         true                            (* Don't close the window. *)
&gt;      )
&gt;   in
&gt;
&gt;   window#connect#destroy ~callback:GMain.quit;
&gt;   window#event#connect#delete ~callback:quit;
&gt;   quit_item#connect#activate ~callback:(fun () -&gt; quit (); ());
&gt;
&gt; I think there's definitely a case for being able to write:
&gt;
&gt;   if !test_id = 0 then (	(* Not in a test - can quit immediately. *)
&gt;     GMain.Main.quit ();
&gt;     return false
&gt;   );
&gt;
&gt;   (* .. rest of code ... *)
&gt;
&gt; But perhaps, as you say, I'm missing the functional solution to this.
&gt;
&gt; (I can dig around and find some more examples like this if it would help).
&gt;
&gt; Rich.
&gt;
&gt; --
&gt; Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
&gt; Merjis Ltd. http://www.merjis.com/ - all your business data are belong to
&gt; you.
&gt; MAKE+ is a sane replacement for GNU autoconf/automake. One script
&gt; compiles,
&gt; RPMs, pkgs etc. Linux, BSD, Solaris.
&gt; http://www.annexia.org/freeware/makeplus/
&gt;
&gt; -------------------
&gt; To unsubscribe, mail caml-list-request@inria.fr Archives:
&gt; http://caml.inria.fr
&gt; Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ:
&gt; http://caml.inria.fr/FAQ/
&gt; Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
&gt;

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

