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 52D317FE44 for ; Mon, 4 Jul 2016 23:56:15 +0200 (CEST) IronPort-PHdr: 9a23:5pakKB/QdadlMf9uRHKM819IXTAuvvDOBiVQ1KB92+McTK2v8tzYMVDF4r011RmSDN2dsagP0reP+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2WVTerzWI4CIIHV2nbEwud7yzQNSZ1pnun8mJuLTrKz1SgzS8Zb4gZD6Xli728vcsvI15N6wqwQHIqHYbM85fxGdvOE7B102kvpT41NdZ/i9Ro/Ms8dJbGeW/JvxgDO8QMDNzHGcu+8zt/QfES0Ol/HYQX38SlQUAVwfC9w77WNLv9yHSqed3niWXa57YV7cxDBar5L52RQSgpy4dLT827Wyf3sN5lrharw+sjxl2346SZoiaM+t3O76bdNhcR3IXDZUZbDBIHo7pN9hHNOEGJ+sN6tCl/1Y= Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=garrigue@math.nagoya-u.ac.jp; spf=None smtp.mailfrom=garrigue@math.nagoya-u.ac.jp; spf=None smtp.helo=postmaster@mailhost.math.nagoya-u.ac.jp 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: A0ABAAAL23pXlwWCBoVbFoN+fLQ6hn0ihXYCgXQQAQEBAQEBAQERAQEBAQEIFgdQgjKCGgEBBAEjBBkDATUBAQMLCxgCAhgOAgJXBog7Bw+odWeEQwcChxGDSgEBAQEBAQEDAQEBAQEBAQEWAQiBAYceglWECDiCSTgrgi+OfIochzqHDY8qkAo1gjgigURfAQGHVYE1AQEB X-IPAS-Result: A0ABAAAL23pXlwWCBoVbFoN+fLQ6hn0ihXYCgXQQAQEBAQEBAQERAQEBAQEIFgdQgjKCGgEBBAEjBBkDATUBAQMLCxgCAhgOAgJXBog7Bw+odWeEQwcChxGDSgEBAQEBAQEDAQEBAQEBAQEWAQiBAYceglWECDiCSTgrgi+OfIochzqHDY8qkAo1gjgigURfAQGHVYE1AQEB X-IronPort-AV: E=Sophos;i="5.26,576,1459807200"; d="scan'208";a="183773235" 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; 04 Jul 2016 23:56:13 +0200 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 0B6106398 for ; Tue, 5 Jul 2016 06:56:10 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (rabbit-172.math.nagoya-u.ac.jp [172.16.254.254]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 8F24D4142; Tue, 5 Jul 2016 06:56:10 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=math.nagoya-u.ac.jp; h= content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; s=alpha; bh=0QZ+nBijUk843SYjxPly9h74uhk=; b=t8Gn0jnBWD92oJiWam+zL6pKEHJ0 12W9JKumfFEmIDaFIzT0ANXAZKVMHNXZL+YJEVoyw/eQtatzY0KaFGZsA8OX7ENO pBrRDsF5XRp3HbwIzdw5H2AD0DvB6+3aDEZ1erM8FLvHWR4KxaKh1erUO5nfP0yV uUP51lqkUuhOXxQ= DomainKey-Signature: a=rsa-sha1; h=Received:Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=uY7+Ul4cghJv0B9F8GYvdsFIT8w1DXBl7DBamr2BHQJphzBlmEO7LUwJXpFKgfMlFrcg5NOJqTiBn+Bk6zpxRX0S2vdcWcf4q/xn8uyhpDxwpbgNyyJ4p4T9q1uxYFFgscr+bTKUhb96w99BkT7P9NN62xlPYQ/9bIOJbjmLq5o=; c=nofws; d=math.nagoya-u.ac.jp; q=dns; s=alpha Received: from tet.garrigue.jp (58x158x128x157.ap58.ftth.ucom.ne.jp [58.158.128.157]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTPSA id 8F7AC683D; Tue, 5 Jul 2016 06:52:30 +0900 (JST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) From: Jacques Garrigue In-Reply-To: <20160704101918.GB7663@frosties> Date: Tue, 5 Jul 2016 06:56:09 +0900 Cc: OCaML List Mailing Content-Transfer-Encoding: quoted-printable Message-Id: <2B4F34AC-A05C-458B-BC95-C4406A27819F@math.nagoya-u.ac.jp> References: <5777F87C01E101EA0039001D_0_1002@p057> <9F10B996-F8B0-48A7-A5A9-21A05EE54AB1@math.nagoya-u.ac.jp> <20160704101918.GB7663@frosties> To: Goswin von Brederlow X-Mailer: Apple Mail (2.3124) Subject: Re: [Caml-list] question: what is the recommended use case of `val` in class type On 2016/07/04 19:19, Goswin von Brederlow wrote: >=20 > On Sun, Jul 03, 2016 at 03:23:35PM +0900, Jacques Garrigue wrote: >> Hi Hongo, >>=20 >> You may want to have a look at a small camlp4 syntax extension I wrote a= long time ago, >> which allows to do what you say. >> Using it, one would write: >>=20 >> val mutable x with accessor >>=20 >> to say that it can be accessed through the x and x_set methods. >>=20 >> The code is here: >> http://www.math.nagoya-u.ac.jp/~garrigue/code/ocaml.html >>=20 >> Note that I didn=E2=80=99t try to support functional state changes, i.e.= adding a method >> method x_upd x=E2=80=99 =3D {< x =3D x=E2=80=99 >} >>=20 >> Jacques >=20 > What's the point of x then? Wouldn't it make more sense to only expose > the accessors so even derived classes will go through them instead of > accessing x directly? Maybe, if OCaml were an object-oriented language. But the accessor approach doesn=E2=80=99t mix too well with multiple inheri= tance, whereas ocaml instance variables do. > Question: Can ppx attributes generate the accessors but also hide the > "val mutable x" when no mli file is present? Not so easy to do, because you need to write an explicit class interface to= hide the instance variable, and for this you need to write the type of the metho= ds x and x_set. Here is some code that does it, and could be translated into an extension: class c (x : int) =3D object inherit (fun x -> object val mutable x =3D x method x =3D x method x_set= y =3D x <- y end : 'a -> object method x : 'a method x_set : 'a -> unit e= nd) x end;; One could generate the inherit line. Jacques=