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 PAA31853; Mon, 25 Jun 2001 15:29:22 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA31779 for ; Mon, 25 Jun 2001 15:29:21 +0200 (MET DST) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f5PDTKL25325 for ; Mon, 25 Jun 2001 15:29:20 +0200 (MET DST) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id PAA24961 for caml-list@inria.fr; Mon, 25 Jun 2001 15:29:20 +0200 (MET DST) Date: Mon, 25 Jun 2001 15:29:20 +0200 From: Markus Mottl To: OCAML Subject: [Caml-list] "polymorphic" exceptions? Message-ID: <20010625152919.A18486@miss.wu-wien.ac.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, not long ago there was an article here about using type variables to parameterize local modules. I just came across a class of problems where this seems like a very nice feature: having "polymorphic" exceptions. E.g.: type index let add ord_el (el : 'el) map = let module M = struct exception Found of index * 'el end in try (* try to add new node or raise exception if key already exists *) ... with Found (index, node) -> update_node index { node with el = el } map.nodes It is really a pity that it is not allowed to write exception Found of index * 'el even though the type variable is bound in "el : 'el". This seems perfectly safe to me, because only the body of "add" can see the module and knows what 'el is when catching the exception. Code outside cannot access the module and therefore cannot catch the exception, which could be unsound if 'el is not known at this point. As was mentioned in the former article, one can also use this trick to parameterize local functor arguments using type variables that are bound in the enclosing expression: surely also useful more often than once. Is there any chance that this could be added to the language? This wouldn't introduce any new concepts, but make some cases more general. Best regards, Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl ------------------- 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