caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yaron Minsky <yminsky@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Strings
Date: Sat, 4 Apr 2009 19:35:24 -0400	[thread overview]
Message-ID: <891bd3390904041635x6a6997ddpc1e12f90d0fc3153@mail.gmail.com> (raw)
In-Reply-To: <87ocvc6qa1.fsf@frosties.localdomain>

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

On Sat, Apr 4, 2009 at 5:51 PM, Goswin von Brederlow <goswin-v-b@web.de>wrote:

> Mutable/Immutable can really nicely done with phantom types and is
> independent of the data structure used. It works for strings, lists,
> arrays, sets, trees, ... and I think all standard modules should have
> it. The official standard lib is rather lacking there but that is why
> there is Batteries. The more I hear/see of it the more I like it.


On this note, there's a small variation on this idea that we've experimented
with at Jane Street that I think is worth mentioning.  When people do this
kind of thing, they usually have two phantom tags, "immutable" and
"mutable", but, there is another natural one to add: "readonly".

A mutable value is, as one would expect, a value that can be modified; and
an immutable value is one that can not be modified.  A readonly value is one
that can not be modified, but that might change nonetheless because
somewhere else in the program there is a mutable handle to the same
underlying value.  You implement this by making the interface for immutable
and readonly values identical, except that a readonly value can be created
from a mutable value without copying.  Mutable and immutable are typically
the most important types of access control to implement, but readonly can be
useful in special cases, where you have a value that you really want to
mutate, but that you want to control where in the program the mutation can
happen.

There's one extra tradeoff worth mentioning with using phantom types for
controlling mutability, which is that values made immutable in this way are
not quite as good as values that are immutable at the lowest level.  The
reason is that ordinary immutable values are understood by the type system
as such, and this goes into the compiler's understanding of the value
restriction and variance.  This means there are cases where, say, a
phantom-immutable list won't work, but an ordinary immutable list will.

(For those interested in a short and elementary tutorial on how to implement
access control with phantom types, look here:
http://ocaml.janestreet.com/?q=node/11)

y

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

  reply	other threads:[~2009-04-04 23:35 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-03 11:56 Strings Jon Harrop
2009-04-03 12:25 ` [Caml-list] Strings Paolo Donadeo
2009-04-03 14:18 ` Ashish Agarwal
2009-04-03 14:46   ` Jon Harrop
2009-04-03 15:03     ` Daniel Bünzli
2009-04-03 16:52       ` Martin Jambon
2009-04-03 17:50         ` Daniel Bünzli
2009-04-03 19:46           ` Paolo Donadeo
2009-04-03 20:41             ` Harrison, John R
2009-04-04 10:11               ` Jon Harrop
2009-04-04 11:12                 ` David Teller
2009-04-04 11:40                   ` Jon Harrop
2009-04-04 12:34                     ` David Rajchenbach-Teller
2009-04-18 12:31                   ` Arkady Andrukonis
2009-04-04 10:13             ` Jon Harrop
2009-04-03 21:44           ` Goswin von Brederlow
2009-04-04  9:10             ` David Rajchenbach-Teller
2009-04-05 10:06               ` Strings Zheng Li
2009-04-06  9:20                 ` Strings David Rajchenbach-Teller
2009-04-06 10:07                   ` Strings Goswin von Brederlow
2009-04-06 11:03                   ` Strings Zheng Li
2009-04-04 17:11           ` [Caml-list] Strings Kuba Ober
2009-04-04 17:26             ` Jon Harrop
2009-04-05 20:54           ` Richard Jones
2009-04-05 23:40             ` Daniel Bünzli
2009-04-03 18:24         ` Florian Hars
2009-04-03 20:34         ` Arnaud Spiwack
2009-04-04 10:20       ` Jon Harrop
2009-04-04  9:14 ` David Rajchenbach-Teller
2009-04-04  9:26   ` Alp Mestan
2009-04-04 10:55     ` blue storm
2009-04-04 21:51     ` Goswin von Brederlow
2009-04-04 23:35       ` Yaron Minsky [this message]
2009-04-05  9:36         ` David Rajchenbach-Teller
2009-04-05 10:08           ` Alp Mestan
2009-04-05 21:41             ` Goswin von Brederlow
2009-04-05 21:40           ` Goswin von Brederlow
2009-04-05  2:55       ` Jon Harrop
2009-04-05  4:22         ` Edgar Friendly
2009-04-05  7:03           ` Goswin von Brederlow
2009-04-05  6:57         ` Goswin von Brederlow
2009-04-05  7:11           ` Jon Harrop
2009-04-04 10:11   ` Jon Harrop
2009-04-04 21:39   ` Goswin von Brederlow
2009-04-05  7:14   ` Romain Beauxis
2009-04-05  9:34     ` David Rajchenbach-Teller
2009-04-05 21:37     ` Goswin von Brederlow

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=891bd3390904041635x6a6997ddpc1e12f90d0fc3153@mail.gmail.com \
    --to=yminsky@gmail.com \
    --cc=caml-list@yquem.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).