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.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE 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 4CC9CBC91 for ; Mon, 13 Aug 2007 10:52:08 +0200 (CEST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7D8q61q029310 for ; Mon, 13 Aug 2007 10:52:07 +0200 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id l7D8pxaC028809; Mon, 13 Aug 2007 17:52:00 +0900 (JST) Date: Mon, 13 Aug 2007 17:51:56 +0900 (JST) Message-Id: <20070813.175156.220052740.garrigue@math.nagoya-u.ac.jp> To: andre@digirati.com.br Cc: caml-list@inria.fr Subject: Re: [Caml-list] Labeled arguments and polymorphic return types From: Jacques Garrigue In-Reply-To: <1186856252.6007.11.camel@homesick> References: <1186856252.6007.11.camel@homesick> X-Mailer: Mew version 4.2 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 46C01BB6.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; val:01 semantics:01 val:01 compiler:01 nathan:98 polymorphic:01 polymorphic:01 caml-list:01 functions:01 int:01 int:01 define:02 argument:02 argument:02 parameter:02 From: Andre Nathan > Consider the following definition: > > # let f ~a = print_int a; raise Exit;; > val f : a:int -> 'a = > > If I call f without using the argument label, I get the following > warning: > > # f 1;; > Warning X: this argument will not be used by the function. > - : a:int -> 'a = > > The call works if I use the label ("f ~a:1"), if I define f without a > label for its argument, or if I remove the "raise" statement (causing > the return value to be unit instead of 'a). > > Why is this warning generated? Reading your description, I think you are misunderstanding the semantics of labels. Namely, you are only allowed to omit label names if all the arguments are known to be passed, which in particular excludes all functions whose return type is 'a. In that case, a non-labelled argument is assumed to correspond to a (yet unknown) non-labelled formal parameter. The above case is tricky, but here is a simple one: # let f ~a x = a :: x;; val f : a:'a -> 'a list -> 'a list = # f 1 [];; - : int list = [1] # f [];; - : a:'a -> 'a list = In the last line, [] does not replace ~a but x. Now, this explains the above warning: since there is no unlabelled parameter, but the return type is polymorphic, your unlabelled argument will be simply discarded, which is probably not what you wanted. The compiler is kind enough to inform you. Jacques Garrigue