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 A772F7FE36 for ; Sat, 2 Jul 2016 19:08:17 +0200 (CEST) IronPort-PHdr: 9a23:IUdJ9xQmG/yADuvGszRMSx0Ky9psv+yvbD5Q0YIujvd0So/mwa64bByN2/xhgRfzUJnB7Loc0qyN4vimAzRLuM7a+Fk5M7V0HycfjssXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aJBzzOEJPK/jvHcaK1oLshrj0ocWYOl0TzBOGIppKZC2sqgvQssREyaBDEY0WjiXzn31TZu5NznlpL1/A1zz158O34YIxu38I46Fp34d6XK77Z6U1S6BDRHRjajhtpZ6jiR6WbQyJ6XEbGlcWmxxHS1zF/hHzWJir43bSvO563yyQMNf5C7Y5RWLxwb1sTUrOiSwAMzciuEbVh8B5xIhSulr1oR10xIrde8eSNvdyd+XXdMkyQWdRX8hQESdGB9XvPMM0E+MdMLMA/MHGrFwUoE77XFH0CQ== Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=nicolas.ojeda.bar@lexifi.com; spf=None smtp.mailfrom=nicolas.ojeda.bar@lexifi.com; spf=None smtp.helo=postmaster@mx30.yaziba.net Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of nicolas.ojeda.bar@lexifi.com) identity=pra; client-ip=82.138.71.21; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="nicolas.ojeda.bar@lexifi.com"; x-sender="nicolas.ojeda.bar@lexifi.com"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of nicolas.ojeda.bar@lexifi.com) identity=mailfrom; client-ip=82.138.71.21; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="nicolas.ojeda.bar@lexifi.com"; x-sender="nicolas.ojeda.bar@lexifi.com"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mx30.yaziba.net) identity=helo; client-ip=82.138.71.21; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="nicolas.ojeda.bar@lexifi.com"; x-sender="postmaster@mx30.yaziba.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BrAACJ9HdXfRVHilJchBR8Bq0ghwqFBoF5hhgCgRwHORMBAQEBAQEBAREBAQsUCVCCMoIaAQEEARIRVgULCwsDBwIBKgICIQESAQUBFAgGEyKHdAMPCAQKpFyBMT4xizuLRA2EHQEBAQEBAQEDAQEBAQEBIYp1gkOEfoJaBZhfNIc6hH2CEI8qiBeGNBIegQ0CHwGCb4E3bIhwAQEB X-IPAS-Result: A0BrAACJ9HdXfRVHilJchBR8Bq0ghwqFBoF5hhgCgRwHORMBAQEBAQEBAREBAQsUCVCCMoIaAQEEARIRVgULCwsDBwIBKgICIQESAQUBFAgGEyKHdAMPCAQKpFyBMT4xizuLRA2EHQEBAQEBAQEDAQEBAQEBIYp1gkOEfoJaBZhfNIc6hH2CEI8qiBeGNBIegQ0CHwGCb4E3bIhwAQEB X-IronPort-AV: E=Sophos;i="5.26,564,1459807200"; d="scan'208,217";a="225235222" Received: from mx30.yaziba.net ([82.138.71.21]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 02 Jul 2016 19:08:17 +0200 Received: from mta10.int.yaziba.net (unknown [217.117.151.14]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx30.yaziba.net (mx10.yaziba.net) with ESMTPS id 1F1FB1A74A6 for ; Sat, 2 Jul 2016 19:08:16 +0200 (CEST) Received: from mta10.int.yaziba.net (localhost [127.0.0.1]) by mta10.int.yaziba.net (Postfix) with ESMTPS id 42ECACA737 for ; Sat, 2 Jul 2016 19:08:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mta10.int.yaziba.net (Postfix) with ESMTP id 34ACFCA81D for ; Sat, 2 Jul 2016 19:08:16 +0200 (CEST) X-Virus-Scanned: amavisd-new at mta10.int.yaziba.net Received: from mta10.int.yaziba.net ([127.0.0.1]) by localhost (mta10.int.yaziba.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ufHyW2AEXBGj for ; Sat, 2 Jul 2016 19:08:16 +0200 (CEST) Received: from mail-qk0-f172.google.com (mail-qk0-f172.google.com [209.85.220.172]) by mta10.int.yaziba.net (Postfix) with ESMTPSA id BEB6CCA807 for ; Sat, 2 Jul 2016 19:08:15 +0200 (CEST) Received: by mail-qk0-f172.google.com with SMTP id e3so36249595qkd.0 for ; Sat, 02 Jul 2016 10:08:15 -0700 (PDT) X-Gm-Message-State: ALyK8tJw/SFtNwV1shgHHwcIqIPvO+0s1tZwQ/SZIdgjHuZNW2Vjh8Ncd6qladts3sfwfjoS8FGBQzjdobFYYA== X-Received: by 10.55.27.98 with SMTP id b95mr5748606qkb.146.1467479294597; Sat, 02 Jul 2016 10:08:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.237.49.2 with HTTP; Sat, 2 Jul 2016 10:07:55 -0700 (PDT) In-Reply-To: <5777F3B101EB04A200390030_0_983@p057> References: <5777F3B101EB04A200390030_0_983@p057> From: Nicolas Ojeda Bar Date: Sat, 2 Jul 2016 19:07:55 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Hongbo Zhang Cc: gabriel.scherer@gmail.com, caml-list@inria.fr Content-Type: multipart/alternative; boundary=001a1147ec8e11e7240536aa2697 X-DRWEB-SCAN: ok X-VRSPAM-SCORE: -100 X-VRSPAM-STATE: legit X-VRSPAM-CAUSE: gggruggvucftvghtrhhoucdtuddrfeeltddrvddtgddutdejucetufdoteggodetrfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdgjtegkkfeuteenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepjghfhfffkffuvfgtsegrtderredttdejnecuhfhrohhmpefpihgtohhlrghsucfqjhgvuggruceurghruceonhhitgholhgrshdrohhjvggurgdrsggrrheslhgvgihifhhirdgtohhmqeenucfkphepvddtledrkeehrddvvddtrddujedvnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhht X-VRSPAM-EXTCAUSE: mhhouggvpehsmhhtphhouhht Subject: Re: [Caml-list] question: what is the recommended use case of `val` in class type --001a1147ec8e11e7240536aa2697 Content-Type: text/plain; charset=UTF-8 Hi Hongbo, As you observed, `val` can be used via inheritance to expose some private state to subclasses without exposing it to the outside. Cheers Nicolas On Sat, Jul 2, 2016 at 7:02 PM, Hongbo Zhang (BLOOMBERG/ 731 LEX) < hzhang295@bloomberg.net> wrote: > Thanks for your reply. But if `val` is not accessible from outside, why it > is the part of class type signature, any reason for this design? > > 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 > `val` in class type > > Objects have some private state, and they expose methods that can be > called from the outside. "val" fields correspond to such private state, > they are not accessible from outside and are thus not part of an object's > type. > > You can always expose a value field to the outside through a "getter" > method 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 > against good encapsulation. > > On Sat, Jul 2, 2016 at 12:45 PM, Hongbo Zhang (BLOOMBERG/ 731 LEX) < > hzhang295@bloomberg.net> wrote: > >> Dear all, >> I have a question about val in class type, is it only useful in >> inheritance? >> for example >> class type text = object val mutable text : string end >> let f (x : text ) = x#text >> <#m_1963343833435410216_m_-4902517353790339526_text>;; >> ^ >> Error: This expression has type text >> It has no method text >> Thanks -- Hongbo >> > > --001a1147ec8e11e7240536aa2697 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Hongbo,

As you observed, = `val` can be used via inheritance to expose some private state to subclasse= s without exposing it to the outside.

Cheers
=
Nicolas

On Sat, Jul 2, 2016 at 7:02 PM, Hongbo Zhang (BLOOMBERG/ 731 LEX) <hzhang295@bloomberg.net> wrote:
Thanks for your reply. But if `val` is not acce= ssible from outside, why it is the part of class type signature, any reason= for this design?

From: gabriel.scherer@gmail.com A= t: 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 `val= ` in class type
Objects have some privat= e state, and they expose methods that can be called from the outside. "= ;val" fields correspond to such private state, they are not accessible= from outside and are thus not part of an object's type.

<= div>You can always expose a value field to the outside through a "gett= er" method 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 against good encapsulation.

On Sat, Jul 2, 2016 at 12:45 PM, = Hongbo Zhang (BLOOMBERG/ 731 LEX) <hzhang295@bloomberg.net> wrote:
Dear all,
= I have a question about val in class type, is it only useful in inheritan= ce?
for example
class type text = =3D object val mutable text : string end
l= et f (x : text ) =3D x#text;; = =
^ = = =
Error: This expression has type text = =
It= has no method text
Thanks -- Hongbo

<= /blockquote>
--001a1147ec8e11e7240536aa2697--