caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: Thomas.Colcombet@irisa.fr (Thomas Colcombet)
Cc: caml-list@inria.fr (OCAML)
Subject: Re: hiding the 'mutable' modifier
Date: Fri, 18 Feb 2000 01:31:49 +0100 (MET)	[thread overview]
Message-ID: <200002180031.BAA25050@miss.wu-wien.ac.at> (raw)
In-Reply-To: <38AAAEAC.734A8B13@irisa.fr> from "Thomas Colcombet" at Feb 16, 2000 03:05:32 PM

> 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



      reply	other threads:[~2000-02-18  9:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-16 14:05 Thomas Colcombet
2000-02-18  0:31 ` Markus Mottl [this message]

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=200002180031.BAA25050@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=Thomas.Colcombet@irisa.fr \
    --cc=caml-list@inria.fr \
    /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).