From: John Max Skaller <skaller@ozemail.com.au>
To: nalexander@amavi.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Naming polymorphic variant types
Date: Sat, 24 Aug 2002 08:38:34 +1000 [thread overview]
Message-ID: <3D66B96A.9000505@ozemail.com.au> (raw)
In-Reply-To: <61954.209.139.221.124.1029974665.squirrel@mail.gx.ca>
Nick Alexander wrote:
> Heh, that's what I thought. Oh well... maybe there is a way to do what I
> want anyway. Let's say I have a record, say {a:int; b:int; c:int}. I
> wish to have a function that returns sub-records, say {a:int; b:int} or
> {b:int; c:int}. However, I don't want to (and can't, if I recall, due to
> name clashes) declare all the sub record types.
> I certainly don't understand enough type/category theory to
> extend the system myself.
>
> Am I out of luck?
AFAIK there's no reason it can't be implemented, but the
result would not be compatible with the existing
system. For example:
type t = {a:int; b:int}
let f x = x.a + 1
The type has to be assumed to be
{>a:int} -> int (* #1 *)
or
{a:int} -> int (* #2 *)
with polymorphic records (the declaration of type
t is irrelevant). But the existing system deduces
t -> int
For polymorphic variants, a new syntax was used to
get around the equivalent problem: that seems to be the main
obstacle to me. The obvious candidate is:
let f x = x.`a
just like polymorphic variants. `a means
polymorphic record label after a . or
inside {} in leading position (after '{'
or ';')
It's not clear whether this style,
with automatic conversions (#1):
let f x = x.`a in
ignore(f {`a=1});
ignore(f {`a=1; `b=2}) (* #1 *)
would be better than requiring explicit conversion (* #2 *)
..
f( {`a=1; `b=2) :> {`a:int} ) )(* #2 *)
..
but clearly a physical conversion (actual
run time operation) is required, so that the field
is at the right offset. With polymorphic
variants no physical conversion is required,
it's a compile time typing thing only.
[The typing in presence of mutable fields
may complicate things]
--
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2002-08-23 22:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-22 0:04 Nick Alexander
2002-08-23 22:38 ` John Max Skaller [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-08-21 4:22 Nick Alexander
2002-08-21 5:27 ` Jacques Garrigue
2002-08-21 16:02 ` Nick Alexander
2002-08-21 23:50 ` Jacques Garrigue
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=3D66B96A.9000505@ozemail.com.au \
--to=skaller@ozemail.com.au \
--cc=caml-list@inria.fr \
--cc=nalexander@amavi.com \
/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