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 35E377FEFE for ; Sun, 3 Jul 2016 08:24:10 +0200 (CEST) IronPort-PHdr: 9a23:xOZkIRAAJUinNuhuM1hgUyQJP3N1i/DPJgcQr6AfoPdwSP7zoMbcNUDSrc9gkEXOFd2CrakV06yM6+u6BzRIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TWM5DIfUi/yKRBybrysXNWD14Ltj6vopcWbSj4LrQL1Wal1IhSyoFeZnegtqqwmFJwMzADUqGBDYeVcyDAgD1uSmxHh+pX4p8Y7oGx48sgs/M9YUKj8Y79wDfkBVGxnYCgJ45jLsh/MRwzH1HsVVGpexhpaAwHD40urA7/7tiz9s+BwwibcO8DqG+MaQzOnuoViQwb1hTxPGDcj6mDYl8E42K1SugigqAFy64vdfIHTMvNxebLUOM5cTGEHXN4HBH8JOZ+1c4ZaV7lJBu1ftYSo4gJW9RY= 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: A0ABAABOr3hXlwWCBoVbFoN+fK0mhwqGfyKFdgKBWxABAQEBAQEBAREBAQEBAQgWB1CCMoIaAQEFIwQZAwE1AQEOCw4HAgECAhgOAgIhLggGE4gWAxYPsUNnhEMHAoZcDUSDWQEBAQEBAQEBAQEBAQEBAQEBFwEIgQGHH4JVgkOBfYJJOCuCL458iWg0hzqEfYIQjyqIF4dzNYI4IoFEXwEBiVEBAQE X-IPAS-Result: A0ABAABOr3hXlwWCBoVbFoN+fK0mhwqGfyKFdgKBWxABAQEBAQEBAREBAQEBAQgWB1CCMoIaAQEFIwQZAwE1AQEOCw4HAgECAhgOAgIhLggGE4gWAxYPsUNnhEMHAoZcDUSDWQEBAQEBAQEBAQEBAQEBAQEBFwEIgQGHH4JVgkOBfYJJOCuCL458iWg0hzqEfYIQjyqIF4dzNYI4IoFEXwEBiVEBAQE X-IronPort-AV: E=Sophos;i="5.26,567,1459807200"; d="scan'208";a="183603936" 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; 03 Jul 2016 08:23:39 +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 BB861639A for ; Sun, 3 Jul 2016 15:23:36 +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 2ED014169; Sun, 3 Jul 2016 15:23:36 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=math.nagoya-u.ac.jp; h= subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; s=alpha; bh=dIvW4vtJDOHd6TYUrlkZUCGHL0k=; b=LilDWc6bWuI7MUA6MA63w0hQHvFN HUk5PJaTIY33eG04cn4pCeBmupoHOE/tnbsbI3dUsEXhG0lVaeI1MhbY68+NKJ70 bCOVxUEnanXVcXIVIfL/dSlRNg950q9wJRn64CciSyoVG8agKf2rjiWdZ10Nqipi QMHt4Kh0nuVQKtI= DomainKey-Signature: a=rsa-sha1; h=Received:Subject:Mime-Version:Content-Type:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=u5McUCUcg6Ww9/jdo8ZDdcdYpp9PPBOVqpG5K9V8mv87R9PXQWHFtrYhqn3nAEx/kz5vjSb943katirUMwb46gfJaKwD02wgeZOvu5xWw+zq6SXnsrzicoM8DFNZcFpzNqsQLLYNAxeeA7o0S1joiDufa6KvEFEJvZ3YLUGfvjk=; 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 8951564E8; Sun, 3 Jul 2016 15:19:58 +0900 (JST) Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Content-Type: text/plain; charset=utf-8 From: Jacques Garrigue In-Reply-To: <5777F87C01E101EA0039001D_0_1002@p057> Date: Sun, 3 Jul 2016 15:23:35 +0900 Cc: nicolas.ojeda.bar@lexifi.com, OCaML List Mailing , Gabriel Scherer Content-Transfer-Encoding: quoted-printable Message-Id: <9F10B996-F8B0-48A7-A5A9-21A05EE54AB1@math.nagoya-u.ac.jp> References: <5777F87C01E101EA0039001D_0_1002@p057> To: Hongbo Zhang X-Mailer: Apple Mail (2.3124) Subject: Re: [Caml-list] question: what is the recommended use case of `val` in class type Hi Hongo, You may want to have a look at a small camlp4 syntax extension I wrote a lo= ng time ago, which allows to do what you say. Using it, one would write: val mutable x with accessor to say that it can be accessed through the x and x_set methods. The code is here: http://www.math.nagoya-u.ac.jp/~garrigue/code/ocaml.html Note that I didn=E2=80=99t try to support functional state changes, i.e. ad= ding a method method x_upd x=E2=80=99 =3D {< x =3D x=E2=80=99 >} Jacques On 2016/07/03 02:23, Hongbo Zhang (BLOOMBERG/ 731 LEX) wrote: >=20 > Hi Nicolas, thanks! It matches with my expectation. > I am thinking of overriding such syntax for bucklescript FFI, we can use = either >=20 > class type t =3D object val mutable x : int end=20 > or > class type t =3D object method x : int method x_set : int -> unit end >=20 > Currently I think the former looks better, since the user can tell it is = getter or setter without relying on naming convention > From: nicolas.ojeda.bar@lexifi.com At: 07/02/16 13:08:28 > To: HONGBO ZHANG (BLOOMBERG/ 731 LEX) > Cc: caml-list@inria.fr, gabriel.scherer@gmail.com > Subject: Re: [Caml-list] question: what is the recommended use case of `v= al` in class type > Hi Hongbo, >=20 > As you observed, `val` can be used via inheritance to expose some private= state to subclasses without exposing it to the outside. >=20 > Cheers > Nicolas >=20 > On Sat, Jul 2, 2016 at 7:02 PM, Hongbo Zhang (BLOOMBERG/ 731 LEX) wrote: > Thanks for your reply. But if `val` is not accessible from outside, why i= t is the part of class type signature, any reason for this design? >=20 > From: gabriel.scherer@gmail.com At: 07/02/16 13:00:34 > To: HONGBO ZHANG (BLOOMBERG/ 731 LEX) > Cc: caml-list@inria.fr > Subject: Re: [Caml-list] question: what is the recommended use case of `v= al` in class type > Objects have some private state, and they expose methods that can be call= ed from the outside. "val" fields correspond to such private state, they ar= e not accessible from outside and are thus not part of an object's type. >=20 > You can always expose a value field to the outside through a "getter" met= hod to access it (and a "setter" method to mutate it if relevant), but that= is often considered dubious object-oriented style -- it tends to go agains= t good encapsulation. >=20 > On Sat, Jul 2, 2016 at 12:45 PM, Hongbo Zhang (BLOOMBERG/ 731 LEX) wrote: > Dear all, > I have a question about val in class type, is it only useful in inher= itance? > for example >=20=20 > class type text =3D object val mutable text : string end=20=20=20=20= =20=20 >=20=20 > let f (x : text ) =3D x#text;;=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 > ^=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 > Error: This expression has type text=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 > It has no method text=20=20=20 > Thanks -- Hongbo >=20 >=20