caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nicolas Ojeda Bar <nicolas.ojeda.bar@lexifi.com>
To: Hongbo Zhang <hzhang295@bloomberg.net>
Cc: gabriel.scherer@gmail.com, caml-list@inria.fr
Subject: Re: [Caml-list] question: what is the recommended use case of `val` in class type
Date: Sat, 2 Jul 2016 19:07:55 +0200	[thread overview]
Message-ID: <CADK7aFPSDCz+4F4wHEJisR0zROwY8iQZ=tf332vuJkp0kLf7Yw@mail.gmail.com> (raw)
In-Reply-To: <5777F3B101EB04A200390030_0_983@p057>

[-- Attachment #1: Type: text/plain, Size: 1597 bytes --]

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) <hzhang295@bloomberg.net>
> 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
>>
>
>

[-- Attachment #2: Type: text/html, Size: 3641 bytes --]

  reply	other threads:[~2016-07-02 17:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-02 17:02 Hongbo Zhang (BLOOMBERG/ 731 LEX)
2016-07-02 17:07 ` Nicolas Ojeda Bar [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-07-05 13:00 Hongbo Zhang (BLOOMBERG/ 731 LEX)
2016-07-02 17:23 Hongbo Zhang (BLOOMBERG/ 731 LEX)
2016-07-03  6:23 ` Jacques Garrigue
2016-07-04 10:19   ` Goswin von Brederlow
2016-07-04 21:56     ` Jacques Garrigue
2016-07-02 16:45 Hongbo Zhang (BLOOMBERG/ 731 LEX)
2016-07-02 16:59 ` Gabriel Scherer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADK7aFPSDCz+4F4wHEJisR0zROwY8iQZ=tf332vuJkp0kLf7Yw@mail.gmail.com' \
    --to=nicolas.ojeda.bar@lexifi.com \
    --cc=caml-list@inria.fr \
    --cc=gabriel.scherer@gmail.com \
    --cc=hzhang295@bloomberg.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).