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 77D1D7F712 for ; Sun, 2 Feb 2014 13:50:54 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of tom.j.ridge@googlemail.com) identity=pra; client-ip=209.85.220.46; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="tom.j.ridge@googlemail.com"; x-sender="tom.j.ridge@googlemail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of tom.j.ridge@googlemail.com designates 209.85.220.46 as permitted sender) identity=mailfrom; client-ip=209.85.220.46; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="tom.j.ridge@googlemail.com"; x-sender="tom.j.ridge@googlemail.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-pa0-f46.google.com) identity=helo; client-ip=209.85.220.46; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="tom.j.ridge@googlemail.com"; x-sender="postmaster@mail-pa0-f46.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkoCAAg/7lLRVdwulGdsb2JhbAA+Gg6DNle+WggWDgEBAQEHCwsJEiqCJQEBBUABATcBDwEKCw0uIhIBBQEcBhOHcAEDEQ02nkaLE4RSAQWTEgoZJw2JMxEGk0iYLoEyjwIYKYFlgjU/PA X-IPAS-Result: AkoCAAg/7lLRVdwulGdsb2JhbAA+Gg6DNle+WggWDgEBAQEHCwsJEiqCJQEBBUABATcBDwEKCw0uIhIBBQEcBhOHcAEDEQ02nkaLE4RSAQWTEgoZJw2JMxEGk0iYLoEyjwIYKYFlgjU/PA X-IronPort-AV: E=Sophos;i="4.95,760,1384297200"; d="scan'208";a="56489224" Received: from mail-pa0-f46.google.com ([209.85.220.46]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Feb 2014 13:50:48 +0100 Received: by mail-pa0-f46.google.com with SMTP id rd3so6045903pab.5 for ; Sun, 02 Feb 2014 04:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=IYN7mOcvkOggdA3GVZirZQEG0tLqvQypEjvcSjo3SfM=; b=BaT3CJxbtvhS6ICgFhvzbnXHnJS3IzHr9Me8KByYsQ73kKmHF0Y5Mv2SW3Zuv15kg4 6mNPiG6FYNvK3hs7mkwKvgbm2OlKJpXyDKEUrdTUkxiNox3wmfWLL2jOo+0SPXcl09ef eTkJX8YePCOr3zV21L82hxxDzikxY5Qt8HOmcx7NcEV3KP3Wzvn5BU9aLGo8E+f/klvI s3Ot1CXP6yv6sWwhQF5mpGKpoFxhJqsUUO/Slzpg3ejVW8hXoTcu/8cgugrDOkkLW0NR z3VPK1AZpPhBzoSygE4K3XdpP3d4v9wMwa9xkLaKKe5qoSjOSyLVw7qUCiTaBKkhnLlA Z60A== X-Received: by 10.66.175.4 with SMTP id bw4mr31645833pac.56.1391345446942; Sun, 02 Feb 2014 04:50:46 -0800 (PST) MIME-Version: 1.0 Sender: tom.j.ridge@googlemail.com Received: by 10.70.104.243 with HTTP; Sun, 2 Feb 2014 04:50:26 -0800 (PST) In-Reply-To: References: From: Tom Ridge Date: Sun, 2 Feb 2014 12:50:26 +0000 X-Google-Sender-Auth: InsRtOYMxSrUgzw48Ii7bTlJZ4I Message-ID: To: Jacques Garrigue Cc: OCaml Mailing List Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] Question about objects and method overriding Thanks, that is what I feared. Added as feature request: http://caml.inria.fr/mantis/view.php?id=6314 On 2 February 2014 12:43, Jacques Garrigue wrote: > On 2014/02/02 20:55, Tom Ridge wrote: > >> Dear caml-list, >> >> With records, one can functionally update a field e.g. as >> >> { r with some_field=new_value } >> >> And new_value may, of course, be a function. >> >> With objects, is there similar functionality? e.g. can I write something like >> >> {{ myobj with method some_method=new_method }} >> >> ? >> >> Of course, I could copy the methods from myobj explicitly into a new >> object (and set some_method to new_method), but I might not know all >> the methods available on myobj, and even if I do this becomes >> textually extremely verbose. >> >> Of course, new_method cannot directly refer to self etc. Basically I >> am using objects in a similar way to records, and would like to use >> this functional record update feature. >> >> Thanks >> >> Tom > > > You can copy an object updating a value field, not a method field: > > class point (x:int) = object val x = x method get = x method bump dx = {< x = x+dx >} end > > You can use this for methods too, by having them call a function value field. > However, this kind of update is only available inside methods, which requires some thinking > when designing your code. > > I agree that what you suggest would be nice to have. > There is no majore technical difficulty, but there would be some overhead. > > Jacques Garrigue