Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
bottom types and threaded exits
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-10-02 (08:19)
From: Markus Mottl <mottl@m...>
Subject: Re: bottom types and threaded exits
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

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 _ =
      try while true do print_endline (read_line ()) done
      with End_of_file -> ()
    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,,