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 q0BDb9mT009919 for ; Wed, 11 Jan 2012 14:37:09 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjgCAGuPDU/UTWUHjWdsb2JhbABDhQ+nWCIBAQEBCQkLCRIGIYFyAQEFIwQLAQUIAQE2Ag8JAhgCAgUWCwICCQMCAQIBRQYBDAYCAQGHeKR8aoM3AY4kB4EviViBFppOjH8 X-IronPort-AV: E=Sophos;i="4.71,493,1320620400"; d="scan'208";a="126426892" Received: from mx3.wp.pl ([212.77.101.7]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 11 Jan 2012 14:37:06 +0100 Received: (wp-smtpd smtp.wp.pl 6887 invoked from network); 11 Jan 2012 14:34:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1326288855; bh=Xqh3r6SDdu6oNPeXWtAHlyguSxZNnvloD26reywes8I=; h=From:To:Subject; b=wcqwsL0XEuytTwjNIqcPSZ/o8JA3eU/jxybuLUmNnZ0jY3T63b1+ImiTqSoxFgNhP Hgw+xF1kUPbkTaNSOIt5kCzA9qOU2qT5CRAVtQ+oUNOVRtNyzDVnWJpxosDRo5eHM8 azDfTr+FuX9LzW6iQbg9XG03gJGRj2qjTPJr217w= Received: from 18-161.2-0.pl (HELO [192.168.1.100]) (d0@[91.189.18.161]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with AES256-SHA encrypted SMTP for ; 11 Jan 2012 14:34:14 +0100 Message-ID: <4F0D8FD6.1060605@wp.pl> Date: Wed, 11 Jan 2012 14:34:14 +0100 From: Dawid Toton User-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0) Gecko/20111220 Thunderbird/9.0 MIME-Version: 1.0 To: rossberg@mpi-sws.org, caml-list References: <1326209342.96423.YahooMailNeo@web111502.mail.gq1.yahoo.com> <1326214824.62249.YahooMailNeo@web111507.mail.gq1.yahoo.com> <4F0D6913.4090207@wp.pl> <307f99bdbbb797985a66a4798b2dd1f1.squirrel@mail.mpi-sws.org> In-Reply-To: <307f99bdbbb797985a66a4798b2dd1f1.squirrel@mail.mpi-sws.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000000 [oYOk] Subject: Re: [Caml-list] Re: References and polymorphism On 2012-01-11 12:43, rossberg@mpi-sws.org wrote: > Dawid Toton wrote: >> Why not to just forbid too general 'a ref types? See the example from >> the page cited above (with explicit quantifier added): >> >> let f : forall 'a. 'a -> 'a = >> let r : 'a option ref = ref None in >> fun x -> (* do evil things with the ref cell *) >> let y = !r in >> let () = r := Some x in >> match y with >> | None -> x >> | Some y -> y >> >> The problem is that the 'a variable is bound by a general quantifier and >> at the same time it is used to give a type to the ref cell. But if this >> were forbidden, I see no need for the value restriction at all. For example: >> >> let g : forall 'a. 'a -> 'a = >> fun (x : exists 'b. 'b) -> >> let r : 'b option ref = ref None in >> (* nothing bad can happen *) >> ... > Nothing useful can happen either. You could never read a value back from r > and use/return it as an 'a or for anything else. So why would you want to > store it there in the first place? I can read from r and use it as 'b option. This is useful in general: a mutable store can be used locally to speed up computations. I can imagine working on 'b array to benefit from fast lookup. > Also, I don't quite understand how your type annotations are supposed to > match up. If x : exists 'b. 'b, then f can't be forall 'a. 'a -> 'a. Use de Morgan's laws for quantifiers: (∃x. x) → y ¬((∃x. x) ∧ ¬y) ¬(∃x. (x ∧ ¬y)) ∀x.(¬(x ∧ ¬y)) ∀x.(x → y) I see, this is probably abuse of constructive logic in this case, but I believe the idea stays the same. Dawid