From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id GAA19950; Thu, 1 Nov 2001 06:46:04 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 GAA20210 for ; Thu, 1 Nov 2001 06:46:03 +0100 (MET) Received: from favie.faith.gr.jp (favie.faith.gr.jp [61.127.175.250]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id fA15k1917175 for ; Thu, 1 Nov 2001 06:46:01 +0100 (MET) Received: from localhost (dhcp7.faith.gr.jp [192.168.1.17]) by favie.faith.gr.jp (8.9.3/8.9.3) with ESMTP id OAA15027; Thu, 1 Nov 2001 14:45:46 +0900 To: rinderkn@hugo.int-evry.fr Cc: caml-list@inria.fr Subject: Re: [Caml-list] Optional arguments and type annotations In-Reply-To: <20011031010534.A26259@hugo.int-evry.fr> References: <20011031010534.A26259@hugo.int-evry.fr> 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: <20011101144530J.garrigue@kurims.kyoto-u.ac.jp> Date: Thu, 01 Nov 2001 14:45:30 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Christian RINDERKNECHT > I am used to annotate the top-level functions with their types, and I > was surprised to see that I must write the following to make it > type-check: > > #let bump ?(step:int option) (x:int) = > match step with > None -> x * 2 > | Some y -> x + y > ;; > val bump : ?step:int -> int -> int = > > and then there is a discrepancy between the "int option" annotation in > the .ml and the "int" in the interface. As you can see with the pattern matching, from inside the function step is of type "int option". But since it is optional, when applying the function you can simply pass an argument of type "int", which is reflected by the external type of the function. This is not to say that there is no discrepancy: actually, if you pass an argument with label ?step: instead of ~step:, it has to be of type "int option", so that we could have written "?step:int option -> int -> int". But since an optional argument must always have type "t option", the "option" part is redondant, and omitted in the printed and parsed types (it actually appears inside the type checker). Hope this is not too misleading. Jacques Garrigue ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr