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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 9E828BC58 for ; Wed, 15 Sep 2010 19:59:02 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlYBAEKmkEzRVdc0kGdsb2JhbACDG55GCBUBAQEBCQkMBxEDH6tIiHY8ghSGVS2IVAEBAwWBHYMrdASKLA X-IronPort-AV: E=Sophos;i="4.56,372,1280700000"; d="scan'208";a="57331083" Received: from mail-ew0-f52.google.com ([209.85.215.52]) by mail3-smtp-sop.national.inria.fr with ESMTP; 15 Sep 2010 19:59:02 +0200 Received: by ewy20 with SMTP id 20so387788ewy.39 for ; Wed, 15 Sep 2010 10:59:01 -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 :content-transfer-encoding; bh=RczrwErU2Ag+aC/SMOVqVFrMpQ738TFX96bhhWX1lsM=; b=jJoLkRcgtgJNz57WMORFwQ0CWoM+5WzhKUezphxgU8mPivvgSJCQ5GEG47RX4cymz0 oQ0zEMx+nQJFRvCP1z2IFF/b3lqgWHmDyMxix31PRN+uRsmvy6pyfbwYx2cC8Qa5E8om FylateieKsAU9uAK64gxITSUHOZrSL3wku7uI= 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:content-transfer-encoding; b=bC7fiS8Pg/sMntuv6IU7UloersspV+OfYGhP5B1DRBUwMSeyAneiBZVeed3tkId6Mm f+3K71voVrcA0hL4KJ88Xhdy6NCRRvf6ob4VHXUWh0XWmHF2826NqAo8AyCEu1pYfg8f lpsNM82ennSC44vsXjX1Vj3C7VOG1X3dqdRg0= MIME-Version: 1.0 Received: by 10.213.34.70 with SMTP id k6mr1528517ebd.65.1284573541524; Wed, 15 Sep 2010 10:59:01 -0700 (PDT) Received: by 10.14.18.148 with HTTP; Wed, 15 Sep 2010 10:59:01 -0700 (PDT) In-Reply-To: References: Date: Wed, 15 Sep 2010 18:59:01 +0100 Message-ID: Subject: Re: [Caml-list] mutable and polymorphism From: Radu Grigore To: Andreas Rossberg Cc: caml-list@yquem.inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; mutable:01 polymorphism:01 rossberg:01 rossberg:01 type-checked:01 checker:01 typecheck:01 polymorphic:01 polymorphic:01 wrote:01 faq:01 andreas:01 caml-list:01 oops:01 int:01 On Wed, Sep 15, 2010 at 6:40 PM, Andreas Rossberg wr= ote: > Have a look at this variant of c.ml and its "potential" if it type-checke= d: >> =C2=A0let f =3D let xs =3D ref [] in fun x -> xs :=3D x :: !xs in f 1; f= 'a' Interesting. If I would be a type checker, here's what I'd do. 1. "ref []" tells me that (xs : '_a), because I know refs can't be polymorp= hic. 2. "x :: !xs" tells me that (xs : '_a list) and (x : '_a) 3. "x -> x :: !xs" tells me that (f : '_a -> '_a list) 4. "f 1" tells me that (f : int -> int list) 5. "f 'a'" tells me... OOPS Moreover, I'd have similar thoughts about a variant of a.ml (and a.ml does typecheck!) let xs =3D ref [] in let f =3D fun x -> xs:=3Dx::!xs in f 1; f 'a' On the other hand, here's what I'd do for the original c.ml, which with a few names added is let f =3D let x =3D ref () in fun y -> () in f 1; f 'a' 1. "ref ()" tells me that (x : unit ref) 2. "y -> ()" tells me that (f : 'a -> unit) 3. "f 1" returns () 4. "f 'a'" return () In other words, I would have thought that in your example the problem is that you tried to use a polymorphic reference. (And this problem even appears in the FAQ.) regards, radu