From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA32251 for caml-red; Fri, 9 Feb 2001 10:45:28 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA30985 for ; Fri, 9 Feb 2001 02:20:10 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f191K8H11021 for ; Fri, 9 Feb 2001 02:20:09 +0100 (MET) Received: from localhost (mikan.kurims.kyoto-u.ac.jp [130.54.16.202]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id KAA23885; Fri, 9 Feb 2001 10:19:57 +0900 (JST) To: Sergeiu@optrak.co.uk Cc: caml-list@inria.fr Subject: Re: Optional arguments In-Reply-To: <30273167BD5AD111A5AD00A0C992201725868D@mercury.optrak.co.uk> References: <30273167BD5AD111A5AD00A0C992201725868D@mercury.optrak.co.uk> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20010209101957N.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 09 Feb 2001 10:19:57 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: weis@pauillac.inria.fr From: Serguei Ouklonski > Example1: > > let fn1 a:string (?b = "") = (String.length a) + (String.length b) > > let x = fn1 "test" > > result is function > > Example2: > > let fn1 (?a = "") b:string = (String.length a) + (String.length b) > > let x = fn1 "test" > > result is 4 (number) > > It seems that in both cases result should be 4. > > Have I missed something from OCaml docs? Optional arguments are discarded when you apply a functions to a non-labelled argument _appearing after them_ in the function's type. So in your example, since a is taken before b, b will not be discarded. Since there is no way to discard b in this, the compiler warns you: # let fn1 a ?(b = "") = String.length a + String.length b;; Warning: This optional argument cannot be erased val fn1 : string -> ?b:string -> int = Regards, Jacques Garrigue --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp JG