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 CAA17091; Fri, 21 Sep 2001 02:14:22 +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 CAA17087 for ; Fri, 21 Sep 2001 02:14:20 +0200 (MET DST) Received: from web9208.mail.yahoo.com (web9208.mail.yahoo.com [216.136.129.41]) by nez-perce.inria.fr (8.11.1/8.10.0) with SMTP id f8L0EJf01135 for ; Fri, 21 Sep 2001 02:14:19 +0200 (MET DST) Message-ID: <20010921001418.59933.qmail@web9208.mail.yahoo.com> Received: from [63.195.80.23] by web9208.mail.yahoo.com via HTTP; Thu, 20 Sep 2001 17:14:18 PDT Date: Thu, 20 Sep 2001 17:14:18 -0700 (PDT) From: Charles Martin Subject: [Caml-list] polymorphic variant question 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 have a number of modules A, B, C that share a single data structure between them, all under the control of a central module. Each wants to store different kinds of data in the data structure. I can create a variant type to classify the data by module: data.mli: type ('a, 'b, 'c) t = A of 'a | B of 'b | C of 'c So each of the individual modules then has code that looks like this: a.ml: type ('b, 'c) t = { data : (int, 'b, 'c) Data.t list ref; } b.ml: type ('a, 'c) t = { data : ('a, string, 'c) Data.t list ref; } Then the central module can have code like this: let data = ref [] in let a = { A.data = data } in let b = { B.data = data } in let c = { C.data = data } in The trouble with this approach is that every time I add a new module, I must add a new tag to the classify data type, and update all of my signatures and type declarations in modules A, B, C, etc. This seems wrong since the whole point is to separate these abstractions. I am hoping I can use polymorphic variants to escape this trap. Thus, the code for an individual module would look like this: a.ml: type t = { data : [`A of int] list ref; } Of course, then in the central module the type [`A of a_data] list ref conflicts with the type [`B of b_data] list ref and [`C of c_data] list ref. What I want is for each of modules A, B, and C to have type annotations such as data : [> `A of a_data ] list ref so that the other modules could add their tags, but this of course is an unbound type parameter. I have the feeling this is a very standard OCaml design pattern, and I'm just missing something obvious... can someone lend a hand? Thanks. __________________________________________________ Terrorist Attacks on U.S. - How can you help? Donate cash, emergency relief information http://dailynews.yahoo.com/fc/US/Emergency_Information/ ------------------- 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