From: Edgar Friendly <thelema314@gmail.com>
To: Brighten Godfrey <pbg@cs.berkeley.edu>
Cc: Jon Harrop <jon@ffconsultancy.com>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Record field label locality
Date: Tue, 12 Aug 2008 19:12:19 -0500 [thread overview]
Message-ID: <48A226E3.5050500@gmail.com> (raw)
In-Reply-To: <BCFDFE2C-F8C5-4DCD-8B80-6CEA818308C7@cs.berkeley.edu>
Brighten Godfrey wrote:
> Actually, what I want seems to be the way OCaml treats methods in
> objects: given an object, you can name the method directly without
> mentioning its module. I can write a function
>
> let f x = x#some_method "argument"
>
> where `x' might be an object defined in another module, or locally. Why
> can't records be handled like this?
>
1) Implementation
Record field access is almost identical to array lookup -- internally,
records are stored as arrays and during compilation the field name gets
translated to the correct index to get. But since type information goes
away after compilation (including record field names), there's no way to
do the same kind of dispatch you get with objects.
Then you run into the problem that the record field labels aren't
global, so you could have the same label as different indexes in
different modules. Thus the compiler needs to know which module that
record field came from to do the conversion to field index.
2) Typing of x.field
Given the following:
module M1 = struct type t = { f1 : int } end
module M2 = struct type t2 = { f2 : int; f1: string } end
let get_f1 x = x.f1
How should f1 be typed? M1.t -> int or M2.t2 -> string? And how to
deal with separate compilation, such that M1 and M2 aren't even in the
same file as get_f1?
E.
next prev parent reply other threads:[~2008-08-13 0:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-10 10:04 Brighten Godfrey
2008-08-10 19:38 ` [Caml-list] " Jon Harrop
2008-08-12 21:03 ` Brighten Godfrey
2008-08-13 0:12 ` Edgar Friendly [this message]
2008-08-13 1:17 ` Brighten Godfrey
2008-08-13 12:48 ` Edgar Friendly
2008-08-14 6:38 ` Brighten Godfrey
2008-08-14 10:11 ` David Allsopp
2008-08-13 1:51 ` blue storm
2008-08-13 8:14 ` Richard Jones
2008-08-13 9:30 ` Brighten Godfrey
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=48A226E3.5050500@gmail.com \
--to=thelema314@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=jon@ffconsultancy.com \
--cc=pbg@cs.berkeley.edu \
/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