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 FAA21711; Fri, 30 Mar 2001 05:42:45 +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 FAA21665 for ; Fri, 30 Mar 2001 05:42:44 +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.11.1/8.10.0) with ESMTP id f2U3gg909639 for ; Fri, 30 Mar 2001 05:42:43 +0200 (MET DST) 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 MAA19367; Fri, 30 Mar 2001 12:42:37 +0900 (JST) To: Judicael.Courant@lri.fr Cc: caml-list@inria.fr Subject: [Caml-list] Implicit parameters (was Future of labels) In-Reply-To: <3AC33042.94F387B@lri.fr> References: <20010329094438J.garrigue@kurims.kyoto-u.ac.jp> <3AC33042.94F387B@lri.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: <20010330124237D.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 30 Mar 2001 12:42:37 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > [The following is probably off-topic and probably needs quite a lot of > work to be put in O'Caml but we can expect miracles from the Caml team, > can not we?] > A wish about optionnal arguments: I would use them a lot if they where a > bit more... optionnal, in the style of implicit parameters of > http://citeseer.nj.nec.com/lewis00implicit.html. > > This would be really helpful when defining printers (where you have to > carry everywhere the channel on which you are printing), when you are > defining a type-checker (you must carry the current environment that is > unchanged in all your rules but the one about lambda-abstraction, ...). For those who didn't read the paper, this is really more about dynamic scoping than default parameters. In particular, their framework does not subsume ours (defaults cannot be defined individually for each function). (*They refer to label-selective lambda calculus (the foundation for labeled argument in Caml), with the interesting comment that "it is unclear whether such a change would integrate well in existing functional languages"*) Their system in itself uses the same mechanism as type classes, of putting information into a constraint environment. I do not see how one could do that in ML. You can easily do dynamic scoping in ML (contrary to Haskell), by using references. The only pitfall is that the produced code is not reentrant. let set_dynamic r v f x = let old = !r in try r := v; let y = f x in r := old; y with exn -> r := old; raise exn let r = ref default let f () = !r let g x = set_dynamic r x f () A variant of this can be applied to printers, since by default they call Format.std_formatter. I suppose you might add some better syntax with camlp4. Can this be made to work in a threaded program ? This is a very interesting question... For the specific case of a type checker, optional arguments can help: let rec type_expr env expr = let type_expr ?(env=env) = type_expr env in match expr with ... | Lambda (var, body) -> ... type_expr ~env:(Env.add var ty env) body... If your problem is that you have many such arguments to pass around, then commuting labeled argument can also be helpful: you just have to copy/paste the argument list at each function call, without caring about their order. I hope some of these methods can fit your needs. --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp JG ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr