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 5A77B7F860 for ; Thu, 20 Feb 2014 20:31:03 +0100 (CET) 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.214.41; 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.214.41 as permitted sender) identity=mailfrom; client-ip=209.85.214.41; 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-bk0-f41.google.com) identity=helo; client-ip=209.85.214.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-bk0-f41.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnoBABZXBlPRVdYpm2dsb2JhbABZgz5XqiGVbYEJCBYOAQEBAQEGCwsJFCiCJQEBBScZARsSCwEDDAYFCwMKDSEiAREBBQEKEgYTEgiHVgEDEQ2geoxegw6VHQoZJwMKZIZwEQEFDI4lMweEOASYMIEyjwUYKYRaOw X-IPAS-Result: AnoBABZXBlPRVdYpm2dsb2JhbABZgz5XqiGVbYEJCBYOAQEBAQEGCwsJFCiCJQEBBScZARsSCwEDDAYFCwMKDSEiAREBBQEKEgYTEgiHVgEDEQ2geoxegw6VHQoZJwMKZIZwEQEFDI4lMweEOASYMIEyjwUYKYRaOw X-IronPort-AV: E=Sophos;i="4.97,514,1389740400"; d="scan'208";a="59480820" Received: from mail-bk0-f41.google.com ([209.85.214.41]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 20 Feb 2014 20:31:02 +0100 Received: by mail-bk0-f41.google.com with SMTP id na10so763188bkb.14 for ; Thu, 20 Feb 2014 11:31:02 -0800 (PST) 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:content-type:content-transfer-encoding; bh=3tEax/ELZJXW1tebVZ7EHrRfZlUTnCjclV3WGl+3ZDY=; b=QQWtm7PAiX3qCgFmSx/UY2cxUfimi32OOgdeKuHOnHub3H0PTF/2NTRW6H6XfB3OqW qr7myScxb2w5sKU90quSoDlv/PP010AU1LmdZ3dxt8SSwfRvvcqoab99JgxqpHwN9HvL C8IS07jHR2ScSI3O8CnaxtQHW04fICF6EE+glSaD/3edNjPJe4zSGRFMX9o2TS949ioe hCNMT3QpVEFX3eZKuPYEbIvvJuOV7Z+T+7A8jGpF6CyY0xTC5I5DuCyg5Cf8dhHicBu6 sqe2DT9N7AQYtW6QB6RXD5wDn8b0Lmitm3qOBDVQzZmpMFq8bQ/U15wc6E5/lSROY1h/ DjyA== X-Received: by 10.205.105.134 with SMTP id dq6mr1038642bkc.58.1392924662130; Thu, 20 Feb 2014 11:31:02 -0800 (PST) MIME-Version: 1.0 Received: by 10.205.45.5 with HTTP; Thu, 20 Feb 2014 11:30:20 -0800 (PST) In-Reply-To: <002201cf2e6c$e2696f60$a73c4e20$@metastack.com> References: <002201cf2e6c$e2696f60$a73c4e20$@metastack.com> From: Gabriel Scherer Date: Thu, 20 Feb 2014 20:30:20 +0100 Message-ID: To: David Allsopp Cc: OCaml List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Constraining mutability of record types with interfaces 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 =3D { contents : 'a } val get : 'a ref -> 'a val set : 'a ref -> 'a -> unit end =3D struct type 'a ref =3D { mutable contents : 'a } let get =3D (!) let set =3D (:=3D) 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=E9my's record typing systems in the nineties. On Thu, Feb 20, 2014 at 7:52 PM, David Allsopp wro= te: > Is there a profound reason that I'm missing (possibly to do with > optimisations) why one can't have: > > Foo.mli > type foo =3D {bar : unit} > > Foo.ml > type foo =3D {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