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 KAA00688; Thu, 29 Apr 2004 10:48:58 +0200 (MET DST) 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 KAA00651 for ; Thu, 29 Apr 2004 10:48:48 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i3T8mVjq006286 for ; Thu, 29 Apr 2004 10:48:33 +0200 Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2-20030924/3.7W) with ESMTP id RAA09999; Thu, 29 Apr 2004 17:48:24 +0900 (JST) Date: Thu, 29 Apr 2004 17:48:24 +0900 (JST) Message-Id: <20040429.174824.68545560.garrigue@kurims.kyoto-u.ac.jp> To: henri.dubois-ferriere@epfl.ch Cc: caml-list@inria.fr Subject: Re: [Caml-list] Optional arguments in inherited methods From: Jacques GARRIGUE In-Reply-To: References: <20040429.074806.68548985.garrigue@kurims.kyoto-u.ac.jp> X-Mailer: Mew version 4.0.64 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 jacques:01 implemented:01 non-optional:01 implemented:01 shorthand:01 jacques:01 ocaml:01 garrigue:01 garrigue:01 match:02 henri:03 henri:03 typing:03 argument:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Henri DF > > Unfortunate, but in the case of optional arguments the problem is > > not with typing but with how they are implemented: an optional > > argument of type [t] is actually a non-optional argument of type [t > > option]. They disappear automagically on application, but this means > > that None's are automatically inserted. So applying a function which has > > optional arguments is completely different from a function without > > them (even if the function call looks the same in your source code). > > what about optional arguments which have a default value? i would assume > these are not implemented using options, so would that change anything > here? They are also implemented with options. let f ?(x=0) y = x + y is just a shorthand for let f ?x y = let x = match x with Some x -> x | None -> 0 in x + y (I believe this is explained in the manual) Why is it this way? Just because the ocaml type system is such that we don't want to have values inside types, which is the approach you can see in C++ for instance. Jacques Garrigue ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners