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 6CBA2BC58 for ; Wed, 15 Sep 2010 21:38:22 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlYBAO+9kEzRVdc0kGdsb2JhbACDG55LCBUBAQEBCQkMBxEDH6w0iHY8ghSGUi2IVAEBAwWBHYMrdASKLA X-IronPort-AV: E=Sophos;i="4.56,372,1280700000"; d="scan'208";a="59338450" Received: from mail-ew0-f52.google.com ([209.85.215.52]) by mail2-smtp-roc.national.inria.fr with ESMTP; 15 Sep 2010 21:38:13 +0200 Received: by ewy20 with SMTP id 20so462948ewy.39 for ; Wed, 15 Sep 2010 12:38:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=RscvejgHfUJNZ7eHyrU3Nbf5jYcoqMG9t5TDeOL1KFU=; b=sCriEExP7OAeHyvFb6cQHhsfZBd/dMp8eHiZ23XTkLdMXn4UfTuxUymg4ZOW+EaWtv lL1dTucRUsnd/Drx7OBlhATnrT7w8hYFf5WkMBxq3VVhz+lg+me2FB0LsNEn0UtiPPDH iMNqqaRXNohcKqnS1omIpng0gSVkxy7yd1xGg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=i18RlijlT3Gz73aulWlSDBqEqaEyM1/UIy2yKBhUIqkuvP0khEkQ0GcNsCg5C+b+5j qKYx22zEW+KgfdKvXtqRgPnxUIGFNlUPqYPbBL4hcJw6i19F8D97pi6PZH4iPEj17Y5I +SDLADTQ7hXL499LmH1LSC2fe8EJS9Fw0FW6Q= MIME-Version: 1.0 Received: by 10.213.34.83 with SMTP id k19mr1689246ebd.34.1284579492644; Wed, 15 Sep 2010 12:38:12 -0700 (PDT) Received: by 10.14.18.148 with HTTP; Wed, 15 Sep 2010 12:38:12 -0700 (PDT) In-Reply-To: <878w32g6wh.fsf@frosties.localdomain> References: <878w32g6wh.fsf@frosties.localdomain> Date: Wed, 15 Sep 2010 20:38:12 +0100 Message-ID: Subject: Re: [Caml-list] mutable and polymorphism From: Radu Grigore To: Goswin von Brederlow Cc: Andreas Rossberg , caml-list@yquem.inria.fr Content-Type: text/plain; charset=UTF-8 X-Spam: no; 0.00; mutable:01 polymorphism:01 rephrase:01 compiler:01 compiler:01 ocaml-core:01 semantics:01 mli:01 polymorphic:01 polymorphic:01 wrote:01 caml-list:01 caml:02 let:03 let:03 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 > 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' 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