From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 8B593BC69 for ; Fri, 9 Mar 2007 00:30:37 +0100 (CET) Received: from ipmail03.adl2.internode.on.net (ipmail03.adl2.internode.on.net [203.16.214.135]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l28NUZal005014 for ; Fri, 9 Mar 2007 00:30:36 +0100 Received: from ppp19-103.lns2.syd7.internode.on.net (HELO [192.168.1.201]) ([59.167.19.103]) by ipmail03.adl2.internode.on.net with ESMTP; 09 Mar 2007 10:00:33 +1030 X-IronPort-AV: i="4.14,264,1170595800"; d="scan'208"; a="60059117:sNHT70853818" Subject: Re: [Caml-list] Labels and polymorphism From: skaller To: Nathaniel Gray Cc: OCaml In-Reply-To: References: Content-Type: text/plain Date: Fri, 09 Mar 2007 10:30:28 +1100 Message-Id: <1173396628.6613.33.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 45F09C9B.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; polymorphism:01 listlabels:01 listlabels:01 val:01 arity:01 val:01 arity:01 sourceforge:01 wrote:01 partial:01 exception:01 caml-list:01 functions:01 functions:01 int:01 On Thu, 2007-03-08 at 10:31 -0800, Nathaniel Gray wrote: > I was recently bemoaning the way that folds (especially nested folds) > using longish anonymous functions become very hard to read, since the > argument order is optimized for greatest opportunity for partial > application rather than readability. This led me to think about using > ListLabels in my code, but then I hit this bit of documentation: > > """ > As an exception to the above parameter matching rules, if an > application is total, labels may be omitted. In practice, most > applications are total, so that labels can be omitted in applications. > ... > But beware that functions like ListLabels.fold_left whose result type > is a type variable will never be considered as totally applied. > """ > > Wha?? I'm trying to wrap my head around this but I'm just totally > confused. I thought that playing around in the interpreter would > help, but it just left me more confused: It's simple: # let id x = x;; val id : 'a -> 'a = # id 1;; - : int = 1 id has arity 1 and is fully applied when it has one argument right? # let f x = x * x;; val f : int -> int = # id f 2;; - : int = 4 WOOPS! Here id has TWO arguments ... So the arity of a function returning a type variable is indeterminate, so you cannot tell if it is fully applied or not. Hence the caveat. -- John Skaller Felix, successor to C++: http://felix.sf.net