From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id IAA12787 for caml-redistribution; Fri, 14 Jan 2000 08:55:19 +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 EAA29796 for ; Fri, 14 Jan 2000 04:01:06 +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.8.7/8.8.7) with ESMTP id EAA00730 for ; Fri, 14 Jan 2000 04:01:03 +0100 (MET) Received: from tet.kurims.kyoto-u.ac.jp (tet.kurims.kyoto-u.ac.jp [130.54.16.184]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id MAA25723; Fri, 14 Jan 2000 12:00:59 +0900 (JST) Received: from localhost (localhost [127.0.0.1]) by tet.kurims.kyoto-u.ac.jp (8.9.3/8.9.3) with ESMTP id MAA10664; Fri, 14 Jan 2000 12:00:12 +0900 (JST) (envelope-from garrigue@kurims.kyoto-u.ac.jp) To: mottl@miss.wu-wien.ac.at Cc: caml-list@inria.fr Subject: Re: Initializing default arguments Reply-To: garrigue@kurims.kyoto-u.ac.jp In-Reply-To: Your message of "Thu, 13 Jan 2000 16:05:27 +0100 (MET)" <200001131505.QAA12513@miss.wu-wien.ac.at> References: <200001131505.QAA12513@miss.wu-wien.ac.at> X-Mailer: Mew version 1.93 on Emacs 20.4 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20000114120012E.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 14 Jan 2000 12:00:12 +0900 From: Jacques Garrigue X-Dispatcher: imput version 980905(IM100) Sender: weis From: Markus Mottl > using labels and default arguments. There I found a problem with functions > like: > > let rec tautology ?(:vs = variables t) t = ... > > It is not possible to reference arguments (here: 't') from default > arguments if they appear later in the function definition. It is clear > that this would be problematic if the other argument also had a default > value and if it referenced the first value again (recursion). > > However, I believe it should be always ok to use non-default arguments > regardless of order, because they are always already initialized. We indeed thought about it. It is technically possible, since the compiler automatically moves the computation of [variables t] inside the body of the function. The only difficulty is that it changes the definition of scopes. Currently you can use several times the same variable in a function definition: # let ck x x = x;; val ck : 'a -> 'b -> 'b = With the new semantics you suggest, this would be ambiguous. On the other hand, prohibiting the above function definition might seem reasonable. Another problem is cascading definitions: let sub ?(:pos = 0) ?(:len = String.length s - pos) s = String.sub s pos len Here we want to access the value of pos inside the default definition of len. Again we can consider all these definitions as working in the same scope, and do a topological sort to get the right order. Last, what to do with definitions like: let f ?(:x = y) = fun y -> ... let f ?(:x = y) : int -> int = fun y -> .. Should we refuse both, accept both, accept only the first one ? Currently the parser does not distinguish between the first one and let f ?(:x = y) y = ... Conclusion: this is possible, and if nobody opposes I think it should be in a future release. Since it's a bit tricky to implement I do not say 3.00. By the way, there is a workaround. Write by hand what the compiler generates: let rec tautology ?:vs t = let vs = match vs with None -> variables t | Some x -> x in ... A bit heavier, but works ok in 2.99. Regards, Jacques --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp JG