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 KAA03509 for caml-red; Mon, 2 Oct 2000 10:19:35 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA02491 for ; Sat, 30 Sep 2000 17:19:46 +0200 (MET DST) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.10.0/8.10.0) with ESMTP id e8UFJkX05192; Sat, 30 Sep 2000 17:19:46 +0200 (MET DST) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id RAA23911; Sat, 30 Sep 2000 17:19:39 +0200 (MET DST) Date: Sat, 30 Sep 2000 17:19:39 +0200 From: Markus Mottl To: Pierre Weis Cc: Julian Assange , caml-list@inria.fr Subject: Re: bottom types and threaded exits Message-ID: <20000930171939.B9945@miss.wu-wien.ac.at> References: <200009301425.QAA17425@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2i In-Reply-To: <200009301425.QAA17425@pauillac.inria.fr>; from Pierre.Weis@inria.fr on Sat, Sep 30, 2000 at 16:25:32 +0200 Sender: weis@pauillac.inria.fr On Sat, 30 Sep 2000, Pierre Weis wrote: > Once more I would prefer a more general recursive function, that would > loop for any (even non looping) function. For instance: > > # let rec bottom f = f (); bottom f;; > val bottom : (unit -> 'a) -> 'b = > > and I consider the 'b in the type of bottom as clearly indicating the > looping for ever nature of any application of the bottom function. The name "bottom" might be a bit confusing in this context, because "f" could be a function with observable side effects (e.g. I/O), whereas "bottom" is usually used to indicate non-termination only, which cannot be observed. But this function (with a different name) and others would come handy more often than once, e.g.: let rec forever f = f (); forever f let try_forever e f = try forever f with exn -> if e <> exn then raise exn This would allow: let _ = try_forever End_of_file (fun () -> print_endline (read_line ())); print_endline "Done!" It is much more tedious (and error-prone if one forgets the "begin ... end") to write the following: let _ = begin try while true do print_endline (read_line ()) done with End_of_file -> () end; print_endline "Done!" Maybe functions similar to "forever" and "try_forever" could make it into the standard library? Such loops come up quite often with e.g. servers or I/O-loops in general. Best regards, Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl