From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Andrew Martin <amartin@ibmoto.com>, caml-list@inria.fr
Subject: Re: CamlIDL - stub code generator and COM binding for OCaml
Date: Tue, 9 Mar 1999 17:07:20 +0100 [thread overview]
Message-ID: <19990309170720.03713@pauillac.inria.fr> (raw)
In-Reply-To: <36E042AB.32801982@ibmoto.com>; from Andrew Martin on Fri, Mar 05, 1999 at 02:46:35PM -0600
> I have one concern about the handling of structs. Actually, it's more of a
> concern with Ocaml than with idl, but idl makes the problem more apparent.
>
> How can one deal with two struct types whose members have the same names.
> In Ocaml, for example:
>
> type foo = {a:int; b:int}
> type goo ={a:char; b:char}
>
> How can I now create an object of type foo?
Currently, you can't, and I agree this is a serious problem with
CamlIDL-generated code. (There's also the symmetrical problem of how
do you now access the fields of an object of type foo.)
> It would be nice if I could write
> let x = ({a=4; b=5;}:foo) or
> let x = {foo.a=4; foo.b=4} or even
> let (x:foo) = {a=4; b=4}
Solutions 1 and 3 could be made to work by having a special type
inference rule for record construction when a known record type is
expected by the context. OCaml already does a similar hack for
typing printf format strings. However, it's a hack, and it has fairly
bad properties (e.g. the results of type inference become dependent on
the order in which the type-checker works.)
For access, you'd have to say something like (x : foo).a.
The second solution could be made to work for record construction, but is
syntactically ambiguous for field access: does x.foo.a means "field a
of field foo of x", or "field foo.a of x" ?
> However, if one is defining a caml interface for existing C code,
> the problem is much worse, since the C code will have been written
> without regard for the need to avoid reusing the same field name in
> different struct types.
Right. The problem could also be attacked at the level of CamlIDL by,
for instance,
- adding an attribute "mlname" to struct fields to specify the name of
the label in the Caml code, e.g.
struct s { [mlname(s_a) int a; [mlname(s_b)] int b; };
struct u { [mlname(u_a) int a; [mlname(u_b)] int b; };
However, adding all those names becomes tedious. Maybe CamlIDL could
use some heuristics to find suitably unique Caml label names
(e.g. if all struct field names are unique in the whole interface,
use them, otherwise prefix them by the struct or typedef name).
- putting sub-modules in the generated .ml and .mli files.
For instance, non-object interfaces in the IDL source could be
translated to sub-modules:
interface I1 { struct s1 { int a; int b; }; }
interface I2 { struct s2 { int a; int b; }; }
would become
module I1: sig type struct_s1 = { a :int; b : int } end
module I2: sig type struct_s2 = { a :int; b : int } end
Any other ideas?
- Xavier Leroy
next prev parent reply other threads:[~1999-03-10 9:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-03-05 10:41 Xavier Leroy
1999-03-05 20:46 ` Andrew Martin
1999-03-08 9:41 ` Sven LUTHER
1999-03-09 16:07 ` Xavier Leroy [this message]
1999-03-09 18:54 ` Andrew Martin
1999-03-12 10:47 ` Thierry Bravier
1999-03-10 9:11 ` Pierre Weis
1999-03-10 9:43 ` Jacques GARRIGUE
1999-03-09 21:57 ` doligez
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=19990309170720.03713@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=amartin@ibmoto.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