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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id AD84D7F712 for ; Sun, 2 Feb 2014 13:43:48 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=pra; client-ip=133.6.130.5; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=mailfrom; client-ip=133.6.130.5; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mailhost.math.nagoya-u.ac.jp) identity=helo; client-ip=133.6.130.5; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="postmaster@mailhost.math.nagoya-u.ac.jp"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApcCAE097lKFBoIFdGdsb2JhbABYwXyBFw4BDBUIPIIlAQEEAUMBNQIDCws0ElcGiBAHqh2EWAKUPohcEAeOVjMHgySBFIlLjmOVXQ X-IPAS-Result: ApcCAE097lKFBoIFdGdsb2JhbABYwXyBFw4BDBUIPIIlAQEEAUMBNQIDCws0ElcGiBAHqh2EWAKUPohcEAeOVjMHgySBFIlLjmOVXQ X-IronPort-AV: E=Sophos;i="4.95,760,1384297200"; d="scan'208";a="47481601" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail3-smtp-sop.national.inria.fr with ESMTP; 02 Feb 2014 13:43:45 +0100 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 0EE1863C5; Sun, 2 Feb 2014 21:43:42 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id C3CF44109; Sun, 2 Feb 2014 21:43:41 +0900 (JST) DomainKey-Signature: h=Received:Subject:Mime-Version:Content-Type:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=; c=nofws; d=math.nagoya-u.ac.jp; q=; s=alpha Received: from tanpopo.garrigue.jp (58x158x128x157.ap58.ftth.ucom.ne.jp [58.158.128.157]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTPSA id 7727E4106; Sun, 2 Feb 2014 21:43:41 +0900 (JST) Mime-Version: 1.0 (Mac OS X Mail 7.1 \(1827\)) Content-Type: text/plain; charset=iso-8859-1 From: Jacques Garrigue In-Reply-To: Date: Sun, 2 Feb 2014 21:43:59 +0900 Cc: OCaml Mailing List Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Tom Ridge X-Mailer: Apple Mail (2.1827) Subject: Re: [Caml-list] Question about objects and method overriding On 2014/02/02 20:55, Tom Ridge wrote: > Dear caml-list, >=20 > With records, one can functionally update a field e.g. as >=20 > { r with some_field=3Dnew_value } >=20 > And new_value may, of course, be a function. >=20 > With objects, is there similar functionality? e.g. can I write something = like >=20 > {{ myobj with method some_method=3Dnew_method }} >=20 > ? >=20 > 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. >=20 > 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. >=20 > Thanks >=20 > Tom You can copy an object updating a value field, not a method field: class point (x:int) =3D object val x =3D x method get =3D x method bump dx = =3D {< x =3D x+dx >} end You can use this for methods too, by having them call a function value fiel= d. However, this kind of update is only available inside methods, which requir= es 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=