Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: Pierre Weis <Pierre.Weis@inria.fr>
Cc: Julian Assange <proff@iq.org>, caml-list@inria.fr
Subject: Re: bottom types and threaded exits
Date: Sat, 30 Sep 2000 17:19:39 +0200	[thread overview]
Message-ID: <20000930171939.B9945@miss.wu-wien.ac.at> (raw)
In-Reply-To: <200009301425.QAA17425@pauillac.inria.fr>; from Pierre.Weis@inria.fr on Sat, Sep 30, 2000 at 16:25:32 +0200

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 = <fun>
> 
> 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



  reply	other threads:[~2000-10-02  8:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-23 14:25 Julian Assange
2000-09-24 19:14 ` Pierre Weis
2000-09-25 10:08 ` Remi VANICAT
2000-09-25 18:38   ` John Prevost
2000-09-26  9:16 ` Xavier Leroy
2000-09-30  9:12   ` Julian Assange
2000-09-30 14:25     ` Pierre Weis
2000-09-30 15:19       ` Markus Mottl [this message]
2000-09-30 14:28     ` Stefan Monnier
2000-10-02 13:11       ` Patrick M Doane
2000-10-02 16:28         ` Markus Mottl
2000-10-05 18:39           ` Pierre Weis
2000-09-25 19:56 Damien Doligez

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=20000930171939.B9945@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=Pierre.Weis@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=proff@iq.org \
    /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