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 NAA07234; Wed, 2 May 2001 13:21:14 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA07344 for caml-list@pauillac.inria.fr; Wed, 2 May 2001 13:21:13 +0200 (MET DST) 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 OAA28012 for ; Tue, 1 May 2001 14:45:32 +0200 (MET DST) Received: from wisbech.cl.cam.ac.uk (mta1.cl.cam.ac.uk [128.232.0.15]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f41CjV921993 for ; Tue, 1 May 2001 14:45:32 +0200 (MET DST) Received: from swordfish.cl.cam.ac.uk ([128.232.0.129] ident=exim) by wisbech.cl.cam.ac.uk with esmtp (Exim 3.092 #1) id 14uZX1-0001Kh-00 for caml-list@inria.fr; Tue, 01 May 2001 13:45:31 +0100 Received: from kl216 by swordfish.cl.cam.ac.uk with local (Exim 3.01 #1) id 14uZX1-0005sL-00 for caml-list@inria.fr; Tue, 01 May 2001 13:45:31 +0100 To: caml-list@inria.fr Subject: [Caml-list] Re: two unrelated questions References: <20010501103100X.garrigue@kurims.kyoto-u.ac.jp> From: Ken Friis Larsen Date: 01 May 2001 13:45:31 +0100 In-Reply-To: Jacques Garrigue's message of "Tue, 01 May 2001 10:31:00 +0900" Message-ID: User-Agent: Gnus/5.0807 (Gnus v5.8.7) Emacs/20.6 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk "Jacques" == Jacques Garrigue writes: Jacques> Particularly, local exception definitions are one of the Jacques> rare features present in SML and absent in Caml, and that Jacques> some SML developpers think that Caml is right about :-) But some of us really like that feature because it allows an elegant *user* implementation of dynamic typing. The task is to implement a structure with the signature DYN: module type DYN = sig type dyn val wrap: unit -> ('a -> dyn) * (dyn -> 'a) end The cannonical SML solution is to use exceptions for this. Here is a Caml version of that solution: module Dyn1 : DYN = struct type dyn = exn let wrap () = let module D = struct exception DYN of 'a end in (function x -> D.DYN x), (function D.DYN x -> x) end (But I'm unfortunately not strong enough in O'Caml because this gives the error "Unbound type parameter 'a". How do I fix that? Note that the implementation works as expected if we make 'a a fixed type.) You can argue that you don't need that feature of exceptions just to implement dynamic typing, because DYN can be implemented using closures and references: module Dyn2 : DYN = struct type dyn = unit -> unit let wrap () = let r = ref None in (fun x -> fun () -> r := Some x), (fun f -> ( r := None ; f() ; match !r with Some x -> x | None -> raise (Failure"Using the wrong unwrapper") )) end Cheers, --Ken ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr