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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 8A5FFBC58 for ; Wed, 15 Sep 2010 19:10:32 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjMBAD6bkEzRVde0mWdsb2JhbACDG5BwjVMIFQEBAQEBCAsKBxEiqmaIdjyCFIZRLYhUAQEDBYEdgyt0BIos X-IronPort-AV: E=Sophos;i="4.56,371,1280700000"; d="scan'208";a="69583754" Received: from mail-ey0-f180.google.com ([209.85.215.180]) by mail4-smtp-sop.national.inria.fr with ESMTP; 15 Sep 2010 19:10:32 +0200 Received: by eya25 with SMTP id 25so338452eya.39 for ; Wed, 15 Sep 2010 10:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=VGVUYlYbROMh1MKLPrFlhDyCjJR9JBgEJTwo+o2IY58=; b=riNT85DgIdbVMMrLrSkNF/MFjU3RF5pGLAhczR6umvIr/8alcYjZZJwx/YnZrrdXAj VwCfhGM3GLwWSkuZ+vneJQMdfsl6R3TA5tW/8yav2PA6d2C+7F3I8SW+PQ99oVr1NjO8 bktbvZDn01HXI5cdi+fan04W/a25lPExyzhEo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=oQfIbWq8D2fpcPG1j6uJ8w9s2dJJlR03sBqPBBZofF3Qp2nKX/fFmQuhHrySt+5dXq n5VbgKN6fes4PLqUOq46tC7E4Vnmk+VjDMWMxJVwBt28B2sIntX+pCVUfWVPpXlHi8gM NGERNRHI/6wVqbiKheK5ISTo5J2jT5RvUbVn0= MIME-Version: 1.0 Received: by 10.213.34.77 with SMTP id k13mr1451681ebd.77.1284570626608; Wed, 15 Sep 2010 10:10:26 -0700 (PDT) Received: by 10.14.18.148 with HTTP; Wed, 15 Sep 2010 10:10:26 -0700 (PDT) Date: Wed, 15 Sep 2010 18:10:26 +0100 Message-ID: Subject: mutable and polymorphism From: Radu Grigore To: caml-list@yquem.inria.fr Content-Type: text/plain; charset=UTF-8 X-Spam: no; 0.00; mutable:01 polymorphism:01 mutable:01 polymorphism:01 char:01 compile:01 compile:01 int:01 expression:02 expression:02 groups:02 let:03 let:03 radu:05 fails:05 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? PS: A few hours ago I tried to post from Google Groups, but the message didn't seem to go thru. Apologies if this is a duplicate