From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Julian Assange <proff@iq.org>, caml-list@inria.fr
Subject: Re: bottom types and threaded exits
Date: Tue, 26 Sep 2000 11:16:39 +0200 [thread overview]
Message-ID: <20000926111639.29744@pauillac.inria.fr> (raw)
In-Reply-To: <wx4s37qj6b.fsf@foo.iq.org>; from Julian Assange on Sun, Sep 24, 2000 at 01:25:48AM +1100
> Pervasives.exit is of type int -> 'a
> Here we see ocaml using 'a to represent _|_. This hack is presumably
> so type unification still works in the face of potentially
> non-terminating computations
That's one way of putting it, but as Pierre Weis mentioned, fully
polymorphic types such as 'a appear naturally during type inference
for non-terminating expressions.
The prime example is recursive functions with no bottom case (let rec
f x = f (x + 1)), but raising an exception (raise Exn) also has type 'a.
Semantically, it is correct to assign type 'a to any expression that
never returns normally: there are no values of type 'a, but such
expressions never result in a value.
By the same reasoning, since a call to Pervasives.exit never returns,
it is safe and indeed logical to give it type int -> 'a.
Thread.exit should also have type unit -> 'a; the reason it currently
has type unit -> unit is due to the way it is implemented
(as Thread.kill(Thread.self())), but this is more of an historical
accident.
Finally, concerning "while true do e done", there is only one typing
rule in the type-checker for "while p do e done", which assumes that
"p" may become false and the loop may thus terminate with the result
"()", hence the "unit" type.
It would be semantically sound to give "while true do e done" the type
'a, but it would require a special type-checking rule for the "while"
construct when the predicate is "true", which sounds a bit weird.
However, we already implemented such a special case for "assert false"
(type 'a) w.r.t. "assert cond" (type unit).
- Xavier Leroy
next prev parent reply other threads:[~2000-09-26 19:27 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 [this message]
2000-09-30 9:12 ` Julian Assange
2000-09-30 14:25 ` Pierre Weis
2000-09-30 15:19 ` Markus Mottl
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=20000926111639.29744@pauillac.inria.fr \
--to=xavier.leroy@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