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 5F98ABC58 for ; Wed, 15 Sep 2010 19:40:24 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoEAAJKhkEyLEwExkWdsb2JhbAChZxUBAQEBCQsKBxEFHasXi0YBj08FhUGNLg X-IronPort-AV: E=Sophos;i="4.56,371,1280700000"; d="scan'208";a="57330444" Received: from hera.mpi-sb.mpg.de ([139.19.1.49]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 15 Sep 2010 19:40:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mpi-sb.mpg.de; s=mail200803; h=From:To:In-Reply-To:Subject: References:Message-Id:Content-Type:Content-Transfer-Encoding: Mime-Version:Date:Cc; bh=eIWZiv8+dczy7gZIkjTQaDGFJV9IW9EOyX1sBD/ F9ns=; b=lysjt6jh02ytvvOR6SxC2n2qZtAUxdRnaSP0cgAdO9gQHkijHcWe8Nh IGEuJ0SEiefFIKPY4LkZ1Xs+MkSeEYSZtqrgVP2CiiKIHiijj1Jv1QMfkcSZp4B+ yH8WJSDnBSJ2ng0dm1YfbxUk/5N4M98iBIvb7GVgormfenckw1e8= Received: from maniac.mpi-klsb.mpg.de ([139.19.1.26]:52829) by hera.mpi-sb.mpg.de (envelope-from ) with esmtp (Exim 4.69) id 1Ovvy0-0005SY-Nw; Wed, 15 Sep 2010 19:40:23 +0200 Received: from [80.146.185.83] (port=41115 helo=dhcp-172-28-83-96.muc.corp.google.com) by maniac.mpi-klsb.mpg.de (envelope-from ) with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.69) id 1Ovvy0-0004gY-AG; Wed, 15 Sep 2010 19:40:20 +0200 From: Andreas Rossberg To: Radu Grigore In-Reply-To: Subject: Re: [Caml-list] mutable and polymorphism References: Message-Id: Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v936) Date: Wed, 15 Sep 2010 19:40:19 +0200 Cc: caml-list@yquem.inria.fr X-Mailer: Apple Mail (2.936) X-Spam: no; 0.00; rossberg:01 rossberg:01 mutable:01 polymorphism:01 mutable:01 polymorphism:01 10,:98 char:01 wrote:01 compile:01 compile:01 andreas:01 andreas:01 caml-list:01 int:01 On Sep 15, 2010, at 19:10, Radu Grigore wrote: > Compile the following three files one-by-one. > (*a.ml*) let _ = ref () in let f = fun _ -> () in f 1; f 'a' > (*b.ml*) let f = let _ = () in fun _ -> () in f 1; f 'a' > (*c.ml*) let f = let _ = ref () in fun _ -> () in f 1; f 'a' > The files a.ml and b.ml compile; the file c.ml fails with > Error: This expression has type char > but an expression was expected of type int > Could someone explain why having a mutable field ("contents" in this > case) restricts the polymorphism of f? Have a look at this variant of c.ml and its "potential" if it type- checked: > let f = let xs = ref [] in fun x -> xs := x :: !xs in f 1; f 'a' /Andreas