From: Jason Hickey <jyh@cs.cornell.edu>
To: caml-list@inria.fr
Cc: crary@cs.cornell.edu, hayden@cs.cornell.edu,
Olivier Montanuy <montanuy@lannion.cnet.fr>,
Emmanuel Engel <Emmanuel.Engel@lri.fr>,
Jerome Vouillon <vouillon@clipper.ens.fr>,
Francisco Valverde <fva@tsc.uc3m.es>
Subject: Re: type recursifs et abreviations cyclique and Co
Date: Mon, 24 Nov 1997 23:40:54 -0500 (EST) [thread overview]
Message-ID: <199711250440.XAA25085@cloyd.cs.cornell.edu> (raw)
Although my French is not what I would like, I gather that the feature
of general recursive types in OCaml has been drawn back because it is
prone to error. For instance, the type I originally proposed
type x = x option
is not allowed because types of that form are prone to error. The
solution would be to apply an explicit boxing:
type x = X of x option.
I would like to make an argument against this policy.
1. The interpretation of the general recursive type has a
well-defined type theoretic meaning. For instance, the type
type x = x option
is isomorphic to the natural numbers. The _type_theory_ does not
justify removing it from the language. Why not issue a warning rather
than forbidding the construction? For instance, the following code is
not forbidden:
let flag = (match List.length [] with 0 -> true)
even though constructions of this form are "prone to error,"
and generate warning messages.
2. The policy imposes a needless efficiency penalty on type
abstraction. For instance, suppose we have an abstract type
type 'a t
then we can't form the recursive type
type x = x t
without a boxing. Although the type
type x = X of x t
is equivalent, it requires threading a lot of superfluous X's through
the code, and ocaml will insert an extraneous boxing for each
occurrence of an item of type x in t. Consider an unlabeled
abstract binary tree:
type 'a t = ('a option) * ('a option) (* abstract *)
...
type node = X of node t
Every node is boxed, with a space penalty that is
linear in the number of nodes.
3. If the type system can be bypassed with an extraneous boxing,
type x = x t -----> type x = X of x t
then what is the point?
4. (Joke) All significant programs are "prone to error." Perhaps the
OCaml compiler should forbid them all!
I use this construction extensively in Nuprl (theorem proving)
and Ensemble (communications) applications; do I really need
to change my code?
Jason
next reply other threads:[~1997-11-25 8:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-11-25 4:40 Jason Hickey [this message]
1997-11-25 10:09 ` recursive types Xavier Leroy
1997-11-25 15:43 ` Jason Hickey
-- strict thread matches above, loose matches on Subject: below --
1997-11-25 11:30 type recursifs et abreviations cyclique and Co Cuoq Pascal
1997-11-21 14:38 Patch "shared-vm" for ocaml-1.06 Fabrice Le Fessant
1997-11-21 18:26 ` type recursifs et abreviations cyclique and Co Emmanuel Engel
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=199711250440.XAA25085@cloyd.cs.cornell.edu \
--to=jyh@cs.cornell.edu \
--cc=Emmanuel.Engel@lri.fr \
--cc=caml-list@inria.fr \
--cc=crary@cs.cornell.edu \
--cc=fva@tsc.uc3m.es \
--cc=hayden@cs.cornell.edu \
--cc=montanuy@lannion.cnet.fr \
--cc=vouillon@clipper.ens.fr \
/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