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 SAA24294; Thu, 22 Mar 2001 18:15:06 +0100 (MET) 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 SAA18198 for ; Thu, 22 Mar 2001 18:15:05 +0100 (MET) Received: from shell5.ba.best.com (shell5.ba.best.com [206.184.139.136]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f2MHF3b01796 for ; Thu, 22 Mar 2001 18:15:03 +0100 (MET) Received: from localhost (bpr@localhost) by shell5.ba.best.com (8.9.3/8.9.2/best.sh) with ESMTP id JAA06085; Thu, 22 Mar 2001 09:14:55 -0800 (PST) Date: Thu, 22 Mar 2001 09:14:54 -0800 (PST) From: Brian Rogoff To: Judicael Courant cc: caml-list@inria.fr Subject: Re: [Caml-list] duplication implementation/interface In-Reply-To: <3AB9D372.A359B1F3@lri.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN Content-Transfer-Encoding: QUOTED-PRINTABLE Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 22 Mar 2001, Judicael Courant wrote: > Brian Rogoff a =E9crit : > >=20 > [...] > > What's the problem with the hack I suggested earlier: put the huge vari= ant > > (and other duplicated types) in a "pure" .mli file (I hate using .ml fo= r > > that) and "open"ing it where you need it, once in the .mli file and onc= e in the > > .ml file? This way you reduce the duplication to two lines. > >=20 > > I know some people are open-phobes, but I find this use of open to be > > acceptable. > >=20 >=20 > 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. >=20 > Example : put your type in my_beautiful_type.mli with constructors Node, > Leaf, ..., and where you need it do >=20 > module T =3D My_beautiful_type >=20 > 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, ... >=20 > This is quite elegant IMHO as it makes your code very clear. Oh yes, this is the common solution in Ada-land for "use-phobes" (their analogue of open-phobes :) to long package names. They have it a little=20 better in that "use" can be in any declarative region so it makes it easier to find which module things come from. It is possible to do this=20 in OCaml with the local module feature but I don't see it as much in code= =20 I've read. > 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). Excellent point. However, I don't tend to define that many exceptions, far fewer than the size of variant types (which easily get tens of constructors even for a single type) so that duplication doesn't bother me as much as for types. Still, I should perhaps rethink my aversion to using a ".ml" as the file holding the duplicated info.=20 This entire discussion has the seeds of a few more FAQ entries. Is our esteemed erstwhile moderator going to do it, or should I take a stab and=20 then mail it along? -- Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr