From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id E6383BC48 for ; Sat, 2 Apr 2005 09:50:25 +0200 (CEST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j327oO3O001224 for ; Sat, 2 Apr 2005 09:50:25 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id j327oIDP017480; Sat, 2 Apr 2005 16:50:18 +0900 (JST) Date: Sat, 02 Apr 2005 16:50:09 +0900 (JST) Message-Id: <20050402.165009.129498726.garrigue@math.nagoya-u.ac.jp> To: jon@ffconsultancy.com Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Type error From: Jacques Garrigue In-Reply-To: <200504020229.33295.jon@ffconsultancy.com> References: <200504020229.33295.jon@ffconsultancy.com> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 424E4EC0.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 height:98 ...:98 ...:98 polymorphic:01 expression:01 jacques:01 jacques:01 int:01 int:01 data:02 data:02 width:97 variables:02 variables:02 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: From: Jon Harrop > I've got a type error: > > This type of expression, -> unit, contains type > variables that cannot be generalized > > which appears with the form: > > let f = > let t = ref None in > fun data -> ... > > but not in the unnested form: > > let t = ref None > > let f = > fun data -> ... > > Is that supposed to happen? I thought those two forms were exactly > equivalent. They are not. The criterion to decide whether to generalize type variables in a definition is whether it is syntactically a "value" or not. Since [ref None] is not a value, your first definition ends up not being a value, and cannot be generalized. The second one is ok, because probably t is later constrained to have a specific type (not containing type variables) and f is now a "value" and can be properly generalized. Note also that this error message does not occur if you provide an interface for your module. But you may in place have a message about a type not being included in another, if you really expected the function to be polymorphic. Jacques Garrigue