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 WAA16889; Wed, 25 Dec 2002 22:05:44 +0100 (MET) 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 WAA16777 for caml-list@pauillac.inria.fr; Wed, 25 Dec 2002 22:05:44 +0100 (MET) 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 TAA31007 for ; Tue, 24 Dec 2002 19:37:11 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from web40611.mail.yahoo.com (web40611.mail.yahoo.com [66.218.78.148]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id gBOIb9H09933 for ; Tue, 24 Dec 2002 19:37:10 +0100 (MET) Message-ID: <20021224183708.89659.qmail@web40611.mail.yahoo.com> Received: from [63.195.80.23] by web40611.mail.yahoo.com via HTTP; Tue, 24 Dec 2002 10:37:08 PST Date: Tue, 24 Dec 2002 10:37:08 -0800 (PST) From: Ker Lutyn Subject: [Caml-list] dynamically extensible sum types To: caml-list@inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I need a dynamically extensible sum type. I can think of three approaches: (1) Use polymorphic variants: `Foo of a * b, `Bar of c * d * e, etc (2) Use exceptions: exception Foo of a * b, exception Bar of c * d * e, etc (3) Use thunks: (fun () -> foo a b), (fun () -> bar c d e), etc Using exceptions seems somewhat sneaky to me. Does it have any advantages over polymorphic variants? The polymorphic variants seem like they might be better since you could actually limit the domain of certain functions... thus, one part of your program could be constrained to a subrange of the sum type, while other parts could be opened up fully. Until now I have been using the thunking approach in an event-based architecture (each event on the queue is a unit->unit thunk). This seems to work pretty well. But now I'm thinking that the other approaches would allow arbitrary filters to be applied to events; i.e., the thunk approach imposes a "read once" discipline on elements of the sum type, and in some applications you might want "read multiple". I'm not asking the question solely in terms of event-based architectures, though, and I'm interested in others experience with the different approaches to dynamically extensible sum types, and what led you to choose one approach over the others. Thanks! __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com ------------------- 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