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 LAA12468; Thu, 22 Mar 2001 11:27:02 +0100 (MET) 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 LAA13975 for ; Thu, 22 Mar 2001 11:27:01 +0100 (MET) Received: from ext.lri.fr (ext.lri.fr [129.175.15.4]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f2MAR0T05570 for ; Thu, 22 Mar 2001 11:27:00 +0100 (MET) Received: from pc87.lri.fr (IDENT:root@pc87 [129.175.8.106]) by ext.lri.fr (8.11.1/jtpda-5.3.2) with ESMTP id f2MAQxu09011 ; Thu, 22 Mar 2001 11:26:59 +0100 (MET) Received: from lri.fr (IDENT:jcourant@localhost.localdomain [127.0.0.1]) by pc87.lri.fr (8.9.3/jtpda-5.3.2) with ESMTP id LAA16916 ; Thu, 22 Mar 2001 11:26:58 +0100 Message-ID: <3AB9D372.A359B1F3@lri.fr> Date: Thu, 22 Mar 2001 11:26:58 +0100 From: Judicael Courant X-Mailer: Mozilla 4.72 [fr] (X11; U; Linux 2.2.14-5.0 i686) X-Accept-Language: en MIME-Version: 1.0 To: Brian Rogoff CC: caml-list@inria.fr Subject: Re: [Caml-list] duplication implementation/interface References: Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Brian Rogoff a écrit : > [...] > What's the problem with the hack I suggested earlier: put the huge variant > (and other duplicated types) in a "pure" .mli file (I hate using .ml for > that) and "open"ing it where you need it, once in the .mli file and once in the > .ml file? This way you reduce the duplication to two lines. > > I know some people are open-phobes, but I find this use of open to be > acceptable. > As for open-phobes, somebody gave me a good solution a few days ago: you can locally define a module with a very short name. Example : put your type in my_beautiful_type.mli with constructors Node, Leaf, ..., and where you need it do module T = My_beautiful_type then you can use it with a small overhead of 2 chars per use of a constructor of My_beautiful_type: T.Node, T.Leaf, ... This is quite elegant IMHO as it makes your code very clear. As an aside, if you consider applying the same treatment for exceptions (also duplicated), you need to put them in a .ml file (not a .mli) as a .cmo is needed for linking (an exception actually creates at run-time a fresh exception identifier). Judicaël -- Judicael.Courant@lri.fr, http://www.lri.fr/~jcourant/ (+33) (0)1 69 15 64 85 "Montre moi des morceaux de ton monde, et je te montrerai le mien" Tim, matricule #929, condamné à mort. http://rozenn.picard.free.fr/tim.html ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr