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 C0FAA7FAF6 for ; Sun, 30 Nov 2014 16:54:01 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of alphablock@orange.fr) identity=pra; client-ip=80.12.242.134; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="alphablock@orange.fr"; x-sender="alphablock@orange.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of alphablock@orange.fr) identity=mailfrom; client-ip=80.12.242.134; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="alphablock@orange.fr"; x-sender="alphablock@orange.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp.smtpout.orange.fr) identity=helo; client-ip=80.12.242.134; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="alphablock@orange.fr"; x-sender="postmaster@smtp.smtpout.orange.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuQBAEA8e1RQDPKGlGdsb2JhbABbhC+DBYEwrxsBBpsXAQEBAQERAQEBAQcLCwkSMIQsBE0gGgImAiM8E4gqAQMWrQuPRo5vAUoNhi6BLoUJiAyBYINUgVMFkQVphGuDbYIBgnWEXYcjiBcBCwGCJm6BBIFDAQEB X-IPAS-Result: AuQBAEA8e1RQDPKGlGdsb2JhbABbhC+DBYEwrxsBBpsXAQEBAQERAQEBAQcLCwkSMIQsBE0gGgImAiM8E4gqAQMWrQuPRo5vAUoNhi6BLoUJiAyBYINUgVMFkQVphGuDbYIBgnWEXYcjiBcBCwGCJm6BBIFDAQEB X-IronPort-AV: E=Sophos;i="5.07,487,1413237600"; d="scan'208,217";a="110317755" Received: from smtp12.smtpout.orange.fr (HELO smtp.smtpout.orange.fr) ([80.12.242.134]) by mail2-smtp-roc.national.inria.fr with ESMTP; 30 Nov 2014 16:54:01 +0100 Received: from [192.168.1.10] ([90.29.118.40]) by mwinf5d23 with ME id Mru01p0070sNjjN03ru0ja; Sun, 30 Nov 2014 16:54:01 +0100 X-ME-Helo: [192.168.1.10] X-ME-Auth: YWxwaGFibG9ja0B3YW5hZG9vLmZy X-ME-Date: Sun, 30 Nov 2014 16:54:01 +0100 X-ME-IP: 90.29.118.40 From: "Damien Guichard" To: "Caml Mailing List" Content-Type: multipart/alternative; charset="UTF-8"; boundary="DvVev0gOIL3ht2HbpxMaajp4alAdY=_cRV" MIME-Version: 1.0 Date: Sun, 30 Nov 2014 16:53:56 +0100 Message-ID: <512049485139066376@orange.fr> X-Mailer: EssentialPIM Portable v. 4.54 X-Validation-by: alphablock@orange.fr Subject: Re: [Caml-list] Object Features This is a multi-part message in MIME format --DvVev0gOIL3ht2HbpxMaajp4alAdY=_cRV Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello,=20 May be i misunderstand something with point n=C2=B01.=20 Otherwise it seems pretty easy to me :=20 let x =3D 10=20 let y =3D 20=20 let o =3D=20 begin=20 object=20 method x =3D x=20 method y =3D y=20 end=20 end=20 Le 30/11/2014 =C3=A0 05:24:32, Jordan W =C3=A0 =C3=A9cr= it :=20 Hello,=20 I've encountered several situations where I would have benefited from the following features. I am curious what some of the OCaml core developers thi= nk 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 =3D 10 let y =3D 20 let o =3D 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 immedia= te objects (at least in the case when objects are being used as row-polymorphic records). let oldObj =3D object method x =3D 20 method greet =3D "hi" end let newObj =3D {} 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 t= his feature will be of interest to many others. 3. Object matching. let myFunction delta {} =3D x + y + delta let myFunction delta o =3D 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 --DvVev0gOIL3ht2HbpxMaajp4alAdY=_cRV Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello,

May be i misu= nderstand something with point n°1.
Otherwise it seems pretty eas= y to me :

    let x =3D 10
  &nb= sp; let y =3D 20
    let o =3D
   = ; begin
      object
   = ;     method x =3D x
    &nbs= p;   method y =3D y
      end
    end



Le 30/11/2014 à 05:24:32, Jordan W <jordojw@gmail.com> à écrit :
Hello,=20

I've encountered several situations where I would have benefit= ed from the following features. I am curious what some of the OCaml core de= velopers think about them.

1. Object punning:
I understand that object punning on "functional updates&q= uot; to objects was recently added to trunk. This is a nice consistency, bu= t I haven't found a way to perform object punning on methods or values for = object *expressions*.

    let x =3D 10
    let y =3D 20
    let o =3D 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 objec= t values.

2. Object extension: I believe that OCaml immediate objects ar= e 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 su= pport for extending objects (inheritance), but only via classes. I understa= nd that implementing this may complicate dynamic dispatch and/or use of `se= lf`, but perhaps some compromise could be reached - something like a limite= d 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 r= ow-polymorphic records).

    let oldObj =3D object method x =3D 20 method gre= et =3D "hi" end
    let newObj =3D {<oldObj with method x =3D 10 = >}

This is similar to Andreas Rossberg's Record Extensions in Suc= cessorML.

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; ..>} =3D x + = y + delta

    let myFunction delta o =3D match o with
        {<x; y; .. >} -> x + y + = delta


This may be relatively easy to implement (my reaso= ning is that I believe it could even be solved at the parsing stage (not th= at 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

--DvVev0gOIL3ht2HbpxMaajp4alAdY=_cRV--