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 D5EE27FE36 for ; Sat, 2 Jul 2016 19:00:19 +0200 (CEST) IronPort-PHdr: 9a23:Cu4niR8WpVUnfv9uRHKM819IXTAuvvDOBiVQ1KB92+kcTK2v8tzYMVDF4r011RmSDN2dsaoP0rKN+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2WVTerzWI4CIIHV2nbEwud7yzQNaZ1pzsn8mJuLTrKz1SgzS8Zb4gZD6Xli728vcsvI15N6wqwQHIqHYbM85fxGdvOE7B102kvpT41NdZ/i9Ro/Ms8dJbGeW/JvxgDO8QMDNzE2cz68fs/SvDRA2Ari8cQGUflBUSUlXt5hX9WZL7vzH18OxwxH/JE9fxSOUbUD647qpvACTjiCodOiRxpG7egNZxgaYduxmhqgZy2abbZYiUMLx1eaaLLoBSfnZIQssED38JOYi7dYZaSrNZZes= Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-io0-f179.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.223.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.223.179 as permitted sender) identity=mailfrom; client-ip=209.85.223.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-io0-f179.google.com) identity=helo; client-ip=209.85.223.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-io0-f179.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0ApAABD8ndXhrPfVdFchBR8BqYwh06GLIUGgXmGGAKBHAc4FAEBAQEBAQEBEQEBAQgLCwkhL4IyghsBBAESER0BGx0BAwELBgUEBwM0AgIiAREBBQEcBhMih3MBAw8IDqRZgTE+MYs7gWqCWgWGMQoZJw1Sg0sBAQEBAQEBAwEBAQEBARkCBhCGGIRNh0GCWgWZE4FYhWKHDY8qjksSHoEPHoJPIoFRIDKIcAEBAQ X-IPAS-Result: A0ApAABD8ndXhrPfVdFchBR8BqYwh06GLIUGgXmGGAKBHAc4FAEBAQEBAQEBEQEBAQgLCwkhL4IyghsBBAESER0BGx0BAwELBgUEBwM0AgIiAREBBQEcBhMih3MBAw8IDqRZgTE+MYs7gWqCWgWGMQoZJw1Sg0sBAQEBAQEBAwEBAQEBARkCBhCGGIRNh0GCWgWZE4FYhWKHDY8qjksSHoEPHoJPIoFRIDKIcAEBAQ X-IronPort-AV: E=Sophos;i="5.26,564,1459807200"; d="scan'208,217";a="225234693" Received: from mail-io0-f179.google.com ([209.85.223.179]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 02 Jul 2016 19:00:19 +0200 Received: by mail-io0-f179.google.com with SMTP id f30so123756966ioj.2 for ; Sat, 02 Jul 2016 10:00:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=0roneZYAc2ILr7AAM4OaK1dPvSB0Rxm5nW38vVpFmX8=; b=RvNaHJfAo1wmJ41hyy18tftLqYjPf57h/8UGS64p4c1aflOU9he+Luecu7uRgASrfj LDW35k0FhFUbibebOnD9truGTdL+rWhs1TOTM0RSEObfTV2Gkb5NCvpr5r78sL69PFbq rzjaldx/MN1HbsEIsZUrdLRwm/q5R1XtFfDuQES+MJB9tEOobMP9+F6IbDUL9t5cgh/E dOOFImTfoi5lQG+uko00yOw869yN31jxmHD3gMQQ6irtFe3RU/YbVqkjsSmCShPEisKu iiyGnHLKkaIQ4R6AIzaKqQZEiorNv7qaZ7UPISZ4JiLmTwEMMXlCACu0tLY7aVuwWSLV B1GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=0roneZYAc2ILr7AAM4OaK1dPvSB0Rxm5nW38vVpFmX8=; b=HmNh1zirhLcpoWbqtjXL03HVclmBVpREodKyMujVEJWbwybsYyXskruTjNiB12qIJX JsYdqHPGU+YLKGXv/zlZrARusYdURjEpwos9KUsQyRc5oBluUNZyqWb6EuxJVkjN/O69 hlRj4bi6ll6D3ohRwcs6WXTqiiT+bUtP9uZirC4SNrLyLqziSuRCCJwxeOqwrwZShsUO XKmJrskqVhzBeUJgsRkEJWGDlLzQ7m56nZ0M5hlBaM7zVAeXkeU6hyLdziPqgoY0acnc SU4FS4IYAUL57H9K+Ux1dzqfWN9C4I1CviOGSIeRxYK3ASY1/o1TwjNR7bRz3fd+bT9r QFgQ== X-Gm-Message-State: ALyK8tKS6Zm+jdMmKoHylMPVPaMD2O6ceHhvGU/9HOjIy9bSRU9D+5jqHKJytqpmTikxmP266sS9Iqb+ro9t+w== X-Received: by 10.107.169.104 with SMTP id s101mr3039405ioe.19.1467478817660; Sat, 02 Jul 2016 10:00:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.68.130 with HTTP; Sat, 2 Jul 2016 09:59:38 -0700 (PDT) In-Reply-To: <5777EFC6021303B200390026_0_980@p057> References: <5777EFC6021303B200390026_0_980@p057> From: Gabriel Scherer Date: Sat, 2 Jul 2016 12:59:38 -0400 Message-ID: To: Hongbo Zhang Cc: caml users Content-Type: multipart/alternative; boundary=001a11421628a463ed0536aa0992 Subject: Re: [Caml-list] question: what is the recommended use case of `val` in class type --001a11421628a463ed0536aa0992 Content-Type: text/plain; charset=UTF-8 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_-4902517353790339526_text>;; > ^ > Error: This expression has type text > It has no method text > Thanks -- Hongbo > --001a11421628a463ed0536aa0992 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Objects have some private state, and they expose meth= ods that can be called from the outside. "val" fields correspond = to such private state, they are not accessible from outside and are thus no= t part of an object's type.

You can always expose a v= alue field to the outside through a "getter" method to access it = (and a "setter" method to mutate it if relevant), but that is oft= en 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 abou= t val in class type, is it only useful in inheritance?
for ex= ample
class type text =3D object val mutable te= xt : string end
let f (x : text ) =3D x#text;; = =
= ^ = =
Error: This expression has typ= e text = =
It has no method text
Thanks --= Hongbo

--001a11421628a463ed0536aa0992--