From: "David Allsopp" <dra-news@metastack.com>
To: "'Brighten Godfrey'" <pbg@cs.berkeley.edu>,
"'Edgar Friendly'" <thelema314@gmail.com>
Cc: "'OCaml List'" <caml-list@yquem.inria.fr>
Subject: RE: [Caml-list] Record field label locality
Date: Thu, 14 Aug 2008 11:11:55 +0100 [thread overview]
Message-ID: <55ED4D00B9044B45A915918B27CC4A35@countertenor> (raw)
In-Reply-To: <746B9595-EA63-4E8F-8994-DF815F71D078@cs.berkeley.edu>
> This is a good point. Thanks for the explanation. I'm having a hard
> time thinking of any case other than =,<,> etc where type information
> would be necessary to determine code generation. On the other hand
> if you break the separation for those operators, maybe it's OK to
> break it for record names as well.
Until OCaml knows the type of the record, field access can't happen either -
because OCaml doesn't know how to map the field name to a field number
within the block representing the value (I'd highly recommend reading
Section 18.2 of the manual - even if you never plan on linking C code, it
gives a good insight into how the OCaml code you write deals with values).
Edgar's point is that after type-checking you throw away all of the type
inferences. So when generating the code, the code generator sees [x.f1]
again and has no idea what type the field [f1] comes from - with x.M2.f1 it
knows to look at the *declared* type [M2.t] and so discovers that the field
named [f1] will be stored in field 1 of the block representing the value.
> > Also you lose the compositionality as before - you can't break this
> > function into two parts because the second line "needs" the first line
> > to work.
>
> It can still work, for example this would work:
>
> let garlic_part_1 () = {M2.f2=5; M2.f1="garlic"}
> let garlic_part_2 x = x.f1
>
> let return_garlic () =
> garlic_part_2 (garlic_part_1 ())
A brief aside (but I think relevant given your complaint!) - you only have
to name one of the fields fully when declaring a record - so your first line
can be:
let garlic_part_1 () = {M2.f2=5; f1="garlic"}
which does save a little typing!
David
next prev parent reply other threads:[~2008-08-14 10:23 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
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 [this message]
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=55ED4D00B9044B45A915918B27CC4A35@countertenor \
--to=dra-news@metastack.com \
--cc=caml-list@yquem.inria.fr \
--cc=pbg@cs.berkeley.edu \
--cc=thelema314@gmail.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;
as well as URLs for NNTP newsgroup(s).