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 RAA09419; Mon, 19 Nov 2001 17:58:41 +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 RAA10663 for ; Mon, 19 Nov 2001 17:58:40 +0100 (MET) Received: from mx5.airmail.net (mx5.airmail.net [209.196.77.102]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id fAJGwY123571 for ; Mon, 19 Nov 2001 17:58:34 +0100 (MET) Received: from covert.black-ring.iadfw.net ([209.196.123.142]) by mx5.airmail.net with smtp (Exim 3.16 #10) id 165rkf-000IdV-00 for caml-list@inria.fr; Mon, 19 Nov 2001 10:58:33 -0600 Received: from rootless.localdomain from [207.136.63.231] by covert.black-ring.iadfw.net (/\##/\ Smail3.1.30.16 #30.55) with esmtp for sender: id ; Mon, 19 Nov 2001 10:59:54 -0600 (CST) Received: (from newman@localhost) by rootless.localdomain (8.10.1/8.10.1) id fAJGWYL30934; Mon, 19 Nov 2001 10:32:34 -0600 (CST) Date: Mon, 19 Nov 2001 10:32:34 -0600 From: William Harold Newman To: caml-list@inria.fr Subject: [Caml-list] functors with style? Message-ID: <20011119103234.A2147@rootless> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I have some questions about functorial programming style. First, a general question. I've used the ocaml-3.02 source as an example when I couldn't guess something about normal style, but it doesn't seem to use functors much. Since it looks like a great deal of work has been done on functors, I expect that there are applications which depend on them. Is there any publicly available Ocaml code which someone could recommend as an example of good functorial style? Then, some specific questions about this toy confidence_interval.mli: module type ORDERING = sig type t val are_ordered: t -> t -> bool end module F: functor (Ordering: ORDERING) -> sig type t val new_t: Ordering.t -> Ordering.t -> t val lo: t -> Ordering.t val hi: t -> Ordering.t end module Int: sig type t val new_t: int -> int -> t val lo: t -> int val hi: t -> int end module Float: sig type t val new_t: float -> float -> t val lo: t -> float end As you can see from this example, my impulse is to give names to modules like $Confidence_interval.Int$ and $Confidence_interval.Float$ (which are defined in confidence_interval.ml as $F(Int_ordering)$ and $F(Float_ordering)$), but that leads to annoyances: * It's annoying to have to specify the redundant signatures for $Int_confidence_interval$ and $Float_confidence_interval$. They're exactly parallel by intent, so I'd like to construct the signatures with a functor-like thing, but from the syntax in section 6.10 of the manual, I'm pretty sure that I can't. * I can't find a way to use the $F$ to define anything in the top level namespace, e.g. $Int_confidence_interval$ or $My_custom_type_confidence_interval$, so I end up with $Confidence_interval.Int$ here and then, when I use $F$ later for other things, $My_custom_type.Confidence_interval$, and the slightly-baroque and not-at-all-parallel names are annoying. It occurs to me that these annoyances could be avoided by keeping the functor-constructed modules anonymous, using explicit functor expressions (e.g. $Confidence_interval.F(Int_order)$ and $Confidence_interval.F(My_custom_type)$) in any code which uses the modules. Would that be a good way to do it? Or is there some other good way? If I did use explicit functor expressions everywhere, it'd be readable enough: if my intent is make the things exactly parallel, then using the explicit functor expressions everywhere would make that obvious, so I'd be happy. But because my previous closest approach to functors was using templates in g++, I'm predisposed to worry about the compiler emitting multiple copies of the functor expansion if I don't give the functor expansion a home in a particular file. Is that an issue in Ocaml? -- William Harold Newman "Furious activity is no substitute for understanding." -- H. H. Williams PGP key fingerprint 85 CE 1C BA 79 8D 51 8C B9 25 FB EE E0 C3 E5 7C ------------------- 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