Hi Nicolas, thanks! It matches with my expectation.
I am thinking of overriding such syntax for bucklescript FFI, we can use either

class type t = object val mutable x : int end 
or
class type t = object method x : int method x_set : int -> unit end

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 `val` in class type
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;;
^
Error: This expression has type text
It has no method text
Thanks -- Hongbo