From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 1C4847FAF6 for ; Sun, 30 Nov 2014 14:45:20 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of philippe.wang.lists@gmail.com) identity=pra; client-ip=209.85.212.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of philippe.wang.lists@gmail.com designates 209.85.212.179 as permitted sender) identity=mailfrom; client-ip=209.85.212.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f179.google.com) identity=helo; client-ip=209.85.212.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="postmaster@mail-wi0-f179.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhACAOwee1TRVdSzlGdsb2JhbABbhC8EgwHLSwcWAQEBAQERAQEBAQcLCwkSMIQDAQEEEhEEGQEzBQEDDAEFBQsNAgImAgIhARIBBQEcBhMiiAkDErBQPTGLM4R2ihonDYYCJgEFDoEgjRWBYINUgVMFkTaFI4NtggGOdYRSGCiBd4NBPjCBBIFDAQEB X-IPAS-Result: AhACAOwee1TRVdSzlGdsb2JhbABbhC8EgwHLSwcWAQEBAQERAQEBAQcLCwkSMIQDAQEEEhEEGQEzBQEDDAEFBQsNAgImAgIhARIBBQEcBhMiiAkDErBQPTGLM4R2ihonDYYCJgEFDoEgjRWBYINUgVMFkTaFI4NtggGOdYRSGCiBd4NBPjCBBIFDAQEB X-IronPort-AV: E=Sophos;i="5.07,487,1413237600"; d="scan'208";a="110308345" Received: from mail-wi0-f179.google.com ([209.85.212.179]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 30 Nov 2014 14:45:19 +0100 Received: by mail-wi0-f179.google.com with SMTP id ex7so14900281wid.0 for ; Sun, 30 Nov 2014 05:45:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=tEE3TGH5FuGejkPFpWJIqwcpsHueZZ1KHd4yu0qv7+w=; b=Fh+kSTgUMj3qHJZSjgNyBCV7L+0G3yE3m9gRPNX2fpa4rUYETAgZM5fNhaBwBUVGz7 zecJqtY9FJ/1iSpCpE4Ck3MZ8TLornb4s5R6NpPprIhOUxeUI8eIYugOTV4etQyjbZtl QPne3e6eF61n6v46zoE2al1syRjJcMFxlewShQ4R7oN3ShQeTUZ+UZ9YM/yCJ4+f8/tG mWBs+btHSaLrPxdbubcmsldJQJwByemWRBkuhiFklVIvSBSVKhREZy10Tdr+M0b/t85/ z2E/w6jLKoL+3zsqosH/WFB8Ijsn+Rj8YYhuKDIH+b3uXwM1ewTC70xRhD+MxcXKNQtG koxg== MIME-Version: 1.0 X-Received: by 10.194.238.3 with SMTP id vg3mr47522860wjc.69.1417355119503; Sun, 30 Nov 2014 05:45:19 -0800 (PST) Sender: philippe.wang.lists@gmail.com Received: by 10.216.243.194 with HTTP; Sun, 30 Nov 2014 05:45:19 -0800 (PST) In-Reply-To: References: Date: Sun, 30 Nov 2014 14:45:19 +0100 X-Google-Sender-Auth: M-9wba2WoJrQriM90lPCgZqTm_Q Message-ID: From: Philippe Wang To: Jordan W Cc: OCaml Mailing List Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Object Features Hi, Just some quick thoughts about 3.: it's not object matching! It looks a little like it, but it's not at all, in the sense that it's not at all like the rest of OCaml's pattern matching stuff. I would somewhat find it useful, but probably too misleading and confusing to encourage having this feature. I was going to say it's not shorter or easier to write it this way, but actually let myFunction delta {} = x + y + delta is a little shorter than something like let myFunction delta (o: ) = o#x + o#y + delta but, still, I don't really see something good in there. Cheers, Philippe Wang On Sun, Nov 30, 2014 at 5:24 AM, Jordan W wrote: > Hello, > > I've encountered several situations where I would have benefited from the > following features. I am curious what some of the OCaml core developers > think about them. > > 1. Object punning: > I understand that object punning on "functional updates" to objects was > recently added to trunk. This is a nice consistency, but I haven't found a > way to perform object punning on methods or values for object *expressions*. > > let x = 10 > let y = 20 > let o = object > method x > method y > end > > Which would create an object with two methods x, y that return x and y > respectively. It may be easy to apply the same convention to object values. > > 2. Object extension: I believe that OCaml immediate objects are fairly > under-appreciated, and most people could find useful applications for them > (at least) in the form of row polymorphic records. However, there are > several features that would make them even more powerful. The feature I long > for the most is object extension (on immediate objects). OCaml has support > for extending objects (inheritance), but only via classes. I understand that > implementing this may complicate dynamic dispatch and/or use of `self`, but > perhaps some compromise could be reached - something like a limited form of > `inherit`, that is allowed to have different semantics and works on > immediate objects (at least in the case when objects are being used as > row-polymorphic records). > > let oldObj = object method x = 20 method greet = "hi" end > let newObj = {} > > This is similar to Andreas Rossberg's Record Extensions in SuccessorML. > > New languages are picking up these extensible record features as described > in Daan Leijen's paper [Extensible Records With Scoped Labels] and I suspect > this feature will be of interest to many others. > > 3. Object matching. > > let myFunction delta {} = x + y + delta > > let myFunction delta o = match o with > {} -> x + y + delta > > > This may be relatively easy to implement (my reasoning is that I believe it > could even be solved at the parsing stage (not that it would be a good idea > to do so)). > > > Thanks for listening. I'm curious if anyone's given thought to implementing > these, and eager to hear thoughts/suggestions. > > Jordan