From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA32066 for caml-redistribution@pauillac.inria.fr; Fri, 18 Feb 2000 10:44:12 +0100 (MET) Resent-Message-Id: <200002180944.KAA32066@pauillac.inria.fr> Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA11067 for ; Fri, 18 Feb 2000 01:31:59 +0100 (MET) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id BAA17793 for ; Fri, 18 Feb 2000 01:31:57 +0100 (MET) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id BAA25050; Fri, 18 Feb 2000 01:31:51 +0100 (MET) From: Markus Mottl Message-Id: <200002180031.BAA25050@miss.wu-wien.ac.at> Subject: Re: hiding the 'mutable' modifier To: Thomas.Colcombet@irisa.fr (Thomas Colcombet) Date: Fri, 18 Feb 2000 01:31:49 +0100 (MET) Cc: caml-list@inria.fr (OCAML) In-Reply-To: <38AAAEAC.734A8B13@irisa.fr> from "Thomas Colcombet" at Feb 16, 2000 03:05:32 PM X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Resent-From: weis@pauillac.inria.fr Resent-Date: Fri, 18 Feb 2000 10:44:12 +0100 Resent-To: caml-redistribution@pauillac.inria.fr > I'd like to do something that looks like : > > module A = > (struct > type t = { mutable field : int } > end : sig > type t = { field : int } > end) The usual idea of a module is to hide the concrete implementation of some data type and to provide for functions that only allow the kind of access you want. So you could write, e.g.: module A : sig type t val field : t -> int end = struct type t = { mutable field : int } let field x = x.field let internal_only x n = x.field <- n end As you can see, the signature to which "A" is restricted, does not show how "t" is implemented (mutable/nonmutable, whatever). It only provides for a function "field" that allows read-only access to the field in type t. However, the user of this module would not (and need not) even know that "t" is implemented as a record with a field of this name. He would only have to write "field foo", for example, to get the information needed. Function "internal_only" destructively updates the record field, but it is not visible to the outside, because it does not appear in the signature. Regards, Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl