From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA09247 for caml-redistribution; Wed, 10 Mar 1999 13:14:51 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA32411 for ; Wed, 10 Mar 1999 10:45:09 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id KAA17719; Wed, 10 Mar 1999 10:45:05 +0100 (MET) Received: from localhost (safran.kurims.kyoto-u.ac.jp [130.54.16.91]) by kurims.kurims.kyoto-u.ac.jp (8.9.1a/3.7W) with ESMTP id SAA03238; Wed, 10 Mar 1999 18:45:03 +0900 (JST) To: Xavier.Leroy@inria.fr Cc: caml-list@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> References: <19990309170720.03713@pauillac.inria.fr> X-Mailer: Mew version 1.93 on Emacs 20.3 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <19990310184356M.garrigue@kurims.kyoto-u.ac.jp> Date: Wed, 10 Mar 1999 18:43:56 +0900 From: Jacques GARRIGUE X-Dispatcher: imput version 980905(IM100) Content-Transfer-Encoding: 7bit Sender: weis From: Xavier Leroy > > 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 JG