From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 919E7BC59 for ; Fri, 17 Sep 2010 09:31:08 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap8BABO2kkzZSMDji2dsb2JhbACiExUBAQEKCwoHDwUfwWuFQQSNLYJh X-IronPort-AV: E=Sophos;i="4.56,381,1280700000"; d="scan'208";a="59420378" Received: from fmmailgate02.web.de ([217.72.192.227]) by mail2-smtp-roc.national.inria.fr with ESMTP; 17 Sep 2010 09:31:08 +0200 Received: from smtp01.web.de ( [172.20.0.243]) by fmmailgate02.web.de (Postfix) with ESMTP id A58A31710D1D4; Fri, 17 Sep 2010 09:31:07 +0200 (CEST) Received: from [78.43.204.177] (helo=frosties.localdomain) by smtp01.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #24) id 1OwVPX-00045k-00; Fri, 17 Sep 2010 09:31:07 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.72) (envelope-from ) id 1OwVPR-0003yd-NP; Fri, 17 Sep 2010 09:31:01 +0200 From: Goswin von Brederlow To: Radu Grigore Cc: Goswin von Brederlow , Andreas Rossberg , caml-list@yquem.inria.fr Subject: Re: [Caml-list] mutable and polymorphism References: <878w32g6wh.fsf@frosties.localdomain> Date: Fri, 17 Sep 2010 09:31:01 +0200 In-Reply-To: (Radu Grigore's message of "Wed, 15 Sep 2010 20:38:12 +0100") Message-ID: <87aangesi2.fsf@frosties.localdomain> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX18Y04LMohekXtjCriDpJc8+SHbBNUaHPB7QciyJ HGqRQqxMmU7vYnEju74xCVPQ2uURpkyhy97VPq0Z2mybIBavPu I7ZGinsGM= X-Spam: no; 0.00; mutable:01 polymorphism:01 rephrase:01 compiler:01 compiler:01 ocaml-core:01 semantics:01 mli:01 mfg:98 polymorphic:01 polymorphic:01 wrote:01 caml-list:01 writes:01 caml:02 Radu Grigore writes: > On Wed, Sep 15, 2010 at 8:10 PM, Goswin von Brederlow wrote: >> In your original a.ml you didn't use the [...] > > Let me rephrase. IMO, both the modified a.ml and the modified c.ml > fail for the same reason: polymorphic references. Therefore, just as > you can't infer from "modified a.ml fails" that "original a.ml should > fail" you can also *not* infer from "modified c.ml fails" that > "original c.ml should fail". > >> Because the compiler is stupid and things with a ref can't >> polymorphic. > > The compiler isn't stupid: Polymorphic references are unsound. See for > example Section 2.2.3 here: > http://caml.inria.fr/pub/docs/u3-ocaml/ocaml-core.html#toc8 It isn't as smart as you. Call it conservative. >> let f y = let x = ref () in (fun y -> ()) y in f 1; f 'a' > > This has different semantics. Consider > let f y = let x = ref 0 in (fun y -> incr x) y in f 1; f 'a' Yes it does. Which makes the value restriction sometimes anyoing. > In any case, I'm more interested in an explanation of what happens, > since in practice I'm quite happy with a.ml (together with hiding the > reference from outside by not putting it in mli). > > regards, > radu Reading up on value restrictions as mentioned in the other mails will give you the technical details. But they get quite technical so you might need some background into the theory of functional languages. MfG Goswin