From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q0AFTBwE026054 for ; Tue, 10 Jan 2012 16:29:11 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApwGAN1YDE9ii1tjeGdsb2JhbAA2DZwokFQBDAkLBxUEIoFtARYcBBUBAhUiARR6AQ4BBhiFW4IpC5c7jlIKgmWEX4kwAQYKAYwIBIg6jFmFSitIiDiDXw X-IronPort-AV: E=Sophos;i="4.71,487,1320620400"; d="scan'208";a="126277853" Received: from nm29.bullet.mail.sp2.yahoo.com ([98.139.91.99]) by mail4-smtp-sop.national.inria.fr with SMTP; 10 Jan 2012 16:29:05 +0100 Received: from [98.139.91.70] by nm29.bullet.mail.sp2.yahoo.com with NNFMP; 10 Jan 2012 15:29:03 -0000 Received: from [98.139.91.58] by tm10.bullet.mail.sp2.yahoo.com with NNFMP; 10 Jan 2012 15:29:03 -0000 Received: from [127.0.0.1] by omp1058.mail.sp2.yahoo.com with NNFMP; 10 Jan 2012 15:29:03 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 752466.67082.bm@omp1058.mail.sp2.yahoo.com Received: (qmail 96528 invoked by uid 60001); 10 Jan 2012 15:29:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1326209343; bh=NaePjfg+eGooCZdjEM/KpO+TlS+m7tIEaVsG+9ZrnlM=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=DLYoTa6YAY1P4Oz8nqjThXo9k9JPIdlkq4LNIJKAkV+FYxPy3UDC38JGg0b9P1iXu0/vA/3pSUmJT1M0wrrnwR+5g6rYE9KgFiR6Jzdqd4e873U4oUbbePGvOjMrSwJvEoPezm9hPrHEmzVTZsxn4h5UsWAaFK95waCFIeQqfvU= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=4U7TrYDd8DAne52gXzMIvtCDGtaRH3mGyHu/0izcM4x3H2MhpZAGFl1wsOiLBG3SisoWRU4eCbRu0eAb0D+5EDfiBNw+TA/e75FExvzWt+jRGkHrXyN6Rh/dM6HqCzUdAwKSrLDre9fvfjmScsurSPtc2b3UwhQnDJx70xEh4IQ=; X-YMail-OSG: adV3UyIVM1lRRpoPjdV5qkRlAkd81qG_Ejk0qEqr3fQmtu5 bl1Uovsvu0vhVQG4u3VTTdftK8iIn7lQKkawi_F1zBYbaVWwsmNLiX6up2XD 5HbA8vT44VHwy96zX68WeiiDgaLdJ0DUoSHWz_Lx23X7tnY.geoMjhBM5ECu bAgeYuszAI8.IFf9iXYIaBFL0nO0qX8LJkaBy.W9Ra8sh6dLylK1vJbpBCtA BVsw6I0RRzXTh56f.fEbNgwFKlPpKXGKfO2xFbnlLfpkyKAR0_Nyrhbj1wSj Qk6UJiUbha9IPsTMRcQqCjqQdipOtqMni5jPbcMKSyrNUOsdUWvvYX0TQFcL T0fTrqs8GXSCqH2WCfpIwdOGTgjURjZKOOPCIaJulS6ZkVRuBnNCuBcNptLG OaJtYiq09Rf0I1aQaJ539qUobgE6PU8JxERg8eoB7XHuofv7rMY02QYOdAr6 _.3WhHJjq Received: from [195.23.39.224] by web111502.mail.gq1.yahoo.com via HTTP; Tue, 10 Jan 2012 07:29:02 PST X-Mailer: YahooMailWebService/0.8.115.331698 Message-ID: <1326209342.96423.YahooMailNeo@web111502.mail.gq1.yahoo.com> Date: Tue, 10 Jan 2012 07:29:02 -0800 (PST) From: Dario Teixeira Reply-To: Dario Teixeira To: O Camlmailinglist MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id q0AFTBwE026054 Subject: [Caml-list] References and polymorphism Hi, Consider functions foobar1 and foobar2: type 'a t = {id: int; x: 'a} let foobar1: 'a -> 'a t =         fun x -> {id = 0; x} let foobar2: 'a -> 'a t =         let ctr = ref 0 in         fun x -> incr ctr; {id = !ctr; x} I would expect them to have the same type, because foobar2's use of a reference cell is kept private.  However, they don't. In fact, foobar2 is not really polymorphic: type 'a t = { id : int; x : 'a; } val foobar1 : 'a -> 'a t val foobar2 : '_a -> '_a t It's easy to get around this issue by putting the reference cell outside of foobar2.  Function foobar3 does just this, and behaves as expected: let next =         let ctr = ref 0 in         fun () -> incr ctr; !ctr let foobar3: 'a -> 'a t =         fun x -> {id = next (); x} Could someone point me to a good explanation of what's going on? (I have the feeling I've read about this restriction before.) Best regards, Dario Teixeira