Re: CamlIDL - stub code generator and COM binding for OCaml

From: Jacques GARRIGUE (garrigue@kurims.kyoto-u.ac.jp)
Date: Wed Mar 10 1999 - 10:43:56 MET


To: Xavier.Leroy@inria.fr
Subject: Re: CamlIDL - stub code generator and COM binding for OCaml
In-Reply-To: Your message of "Tue, 9 Mar 1999 17:07:20 +0100"
        <19990309170720.03713@pauillac.inria.fr>
Message-Id: <19990310184356M.garrigue@kurims.kyoto-u.ac.jp>
Date: Wed, 10 Mar 1999 18:43:56 +0900
From: Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp>

From: Xavier Leroy <Xavier.Leroy@inria.fr>

> > 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" ?

I am and more thinking that allowing labels in some types might be a
good solution.

Then one just has to write.

type foo = Foo of { a: int; b: int }
type goo = Goo of { a: char; b: char }

let x = Foo {a=1;b=2}
let y = Goo {a='a';b='b'}

With extraction, you just need to have pattern matched on the
record. The two following are ok:

fun (Foo {a=a}) -> a
fun (Foo x) -> x.a

and even, if we defined "a:" to be mutable in foo

fun (Foo x) -> x.a <- 3

The last ones may seem strange, but it is clearly unambiguous,
and if I remember correctly caml-light has already something like that
for mutable sum types.

This is an easy solution. If you are ready for something more
far-fetched, we could go for using type information, and use a
restricting scheme to keep principality, as is done in olabl for class
having polymorphic methods. This is safe and correct, and
syntactically very light. In fact, since exactly the same mechanism
would work, this would be very easy to add it to olabl.

---------------------------------------------------------------------------
Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp
                <A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:20 MET