From: prevost@maya.com
To: caml-list@inria.fr
Subject: Class syntax questions
Date: Wed, 20 Jan 1999 15:03:09 -0500 (EST) [thread overview]
Message-ID: <199901202003.PAA19118@zarya.maya.com> (raw)
When trying to write an .mli to embody the types of the DOM interface
the other day, I came across what seemed to be a strange wart in the
language spec.
Specifically, I was trying to do something like the following:
type foo_sum =
| A of a
| B of b
class type any =
object
method to_sum : foo_sum
end
class type a =
object
method a : int
end
class type b =
object
method b : bool
end
(I suspect that the above thing, which acts sort of like "downcasting",
isn't strictly needed to do the things DOM lets you do, since it's also
provided a more reasonable mechanism for accessing children of
different types--but, I want to expose both mechanisms, as the spec
includes them.)
Obviously, the above requires that the types any, a, b, and foo_sum be
corecursive. Unfortunately, there's no way to use "and" with a class
type and a normal type. This means that you need to fall back on
writing things like:
type any = < to_sum : foo_sum >
and a = < a : int; to_sum : foo_sum >
and ...
since < .. > notation can't use inherit. Not too much of a problem
until you're trying to implement something like DOM, which has some
fairly complex interfaces.
In fact, I fear I may have written types doing this which are over large
for the type inference mechanism to handle nicely. Or maybe not. IN
any case, the size of the type declarations makes it difficult to find
what O'Caml thinks is wrong.
Is there any way around this in the language, or was it simply
overlooked?
John.
reply other threads:[~1999-01-21 8:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=199901202003.PAA19118@zarya.maya.com \
--to=prevost@maya.com \
--cc=caml-list@inria.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