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 DD9D2BC37 for ; Tue, 27 Oct 2009 19:25:12 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al0IAFPY5krRVd7Li2dsb2JhbACReYkEPwEBAQoLCgcRBa5BhnGIaAEDAwWEOgSJTA X-IronPort-AV: E=Sophos;i="4.44,634,1249250400"; d="scan'208";a="37096684" Received: from mail-pz0-f203.google.com ([209.85.222.203]) by mail3-smtp-sop.national.inria.fr with ESMTP; 27 Oct 2009 19:25:07 +0100 Received: by pzk41 with SMTP id 41so387217pzk.0 for ; Tue, 27 Oct 2009 11:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:from:date:x-google-sender-auth:message-id:subject:to:cc :content-type:content-transfer-encoding; bh=1OGK5j0MOByp4eHDgs1OqqLqd1dAcdgRyl1GdLaMZBM=; b=vjFJ7ZKdim9sS9c2NXqjryRCQf4wti9PZGNsplG403oCDm3ap6F4JuOp5TBJZorAHb Q4LzV0etU4fnO3uLm2n2Hhx8ccaYPUUq3hkvHHo70LnTBk1mSGGQsF7rI+mu4/yBWrK/ 2qQPoEpSDNRVwv0ECZ0mdmPOKDVSPlvrdNybQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; b=Afg5DxKhK1kxy7H6PWK+vlISMPRNgpwM3A3VshzL60X3u/PXCyG0dfVB8AR5kDnt0h ca2PVEnIECA9ixuIiSTNVPuUCBPliPh39Gc6mKqf+pyWSyBOo3nLiQTXpKz0LjGOxpNG vi8E5pk+ZzmbEY0X2PRz8KvkfpPRArPKaiPlQ= MIME-Version: 1.0 Sender: jake.donham@gmail.com Received: by 10.142.4.41 with SMTP id 41mr1382618wfd.123.1256667906056; Tue, 27 Oct 2009 11:25:06 -0700 (PDT) In-Reply-To: References: From: Jake Donham Date: Tue, 27 Oct 2009 11:24:46 -0700 X-Google-Sender-Auth: 706a4b971f265928 Message-ID: Subject: Re: [Caml-list] A strange typing error with polymorphic variants To: Marc de Falco Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; variants:01 bug:01 mutable:01 sqrt:01 bindings:01 2009:98 2.0:98 2.0:98 polymorphic:01 wrote:01 typing:01 caml-list:01 computation:01 expression:02 expression:02 On Tue, Oct 27, 2009 at 3:28 AM, Marc de Falco wrote: > Hi, I've come across a very strange error, and I'm not sure if it is > a bug or a feature. > > The following code : > type 'a p =3D R of 'a t | E of float > =A0=A0=A0 and 'a t =3D { mutable p : 'a p; c : 'a } > let f =3D > =A0=A0=A0 let x =3D sqrt(2.0) in > =A0=A0=A0 fun () -> { c =3D `A; p =3D E 0.0 } > > generates the error : > =A0 The type of this expression, unit -> _[> `A ] t, > =A0 contains type variables that cannot be generalized > > but if I change the x definition to "let x =3D 2.0 in" then it works. > > Another solution is to add a dummy parameter "let f ?(dummy=3D())" this w= orks > too. I think this is just the value restriction. The type of f is generalized only if the right hand side is a value (rather than an expression needing some computation); in your examples the one that fails is not a value, the others are. It looks like there is a relaxation to allow let bindings which are themselves values. Jake