caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: David Allsopp <dra-news@metastack.com>
Cc: OCaml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Constraining mutability of record types with interfaces
Date: Thu, 20 Feb 2014 20:30:20 +0100	[thread overview]
Message-ID: <CAPFanBGTzuZ7_waPU8z2YTXUs2Kg-BUbZq3Z6RwpCzMZfB4xvQ@mail.gmail.com> (raw)
In-Reply-To: <002201cf2e6c$e2696f60$a73c4e20$@metastack.com>

One reason that would be unsound is that the variance would be
incorrectly inferred from the immutable interface as being covariant.
You could then do things such as:

  module Ref : sig
    type +'a ref = { contents : 'a }
    val get : 'a ref -> 'a
    val set : 'a ref -> 'a -> unit
  end = struct
   type 'a ref = { mutable contents : 'a }
   let get = (!)
   let set = (:=)
  end

Having covariant (shared) references is unsound.

Now it would be possible to give a weaker type meaning not "the field
is immutable" but "you're not allowed to mutate the field, while some
other parts of the program may be". This status would not imply
covariance, and would be supertype of both "immutable" and "mutable"
fields -- there is work in that direction in Didier Rémy's record
typing systems in the nineties.

On Thu, Feb 20, 2014 at 7:52 PM, David Allsopp <dra-news@metastack.com> wrote:
> Is there a profound reason that I'm missing (possibly to do with
> optimisations) why one can't have:
>
> Foo.mli
>         type foo = {bar : unit}
>
> Foo.ml
>         type foo = {mutable bar : unit}
>
> i.e. have field mutability being something which can be constrained by an
> interface in a sort of equivalent way to private types? I'm guessing, as the
> compiler goes to the trouble of explaining the exact error, that there is!
>
>
> David
>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

      reply	other threads:[~2014-02-20 19:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-20 18:52 David Allsopp
2014-02-20 19:30 ` Gabriel Scherer [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=CAPFanBGTzuZ7_waPU8z2YTXUs2Kg-BUbZq3Z6RwpCzMZfB4xvQ@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=dra-news@metastack.com \
    /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).