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 MAA16521; Sun, 2 May 2004 12:24:31 +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 MAA16667 for ; Sun, 2 May 2004 12:24:30 +0200 (MET DST) Received: from out2.smtp.messagingengine.com (out2.smtp.messagingengine.com [66.111.4.26]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i42AOSEV017625 for ; Sun, 2 May 2004 12:24:29 +0200 X-Sasl-enc: aPlVj3mYX24YTzj24q4arQ 1083493459 Received: from [192.168.1.100] (unknown [218.81.128.77]) by mail.messagingengine.com (Postfix) with ESMTP id 6CB8AADCFB1; Sun, 2 May 2004 06:24:18 -0400 (EDT) Date: Sun, 2 May 2004 18:24:15 +0800 (HKT) From: Martin Jambon X-X-Sender: martin@localhost To: Jon Harrop Cc: caml-list@inria.fr Subject: Re: [Caml-list] Functors In-Reply-To: <200405021012.28011.jdh30@cam.ac.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 4094CC5D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 functors:01 implemented:01 checker:01 functor:01 functor:01 functors:01 signoles:01 lri:01 signoles:01 ocamldefun:01 equality:01 compile:02 enforce:02 enforce:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, 2 May 2004, Jon Harrop wrote: > Could Set (and others) be implemented polymorphically by using a comparison > function passed as an argument? > > If so, what would be the implications of this approach? I think: you couldn't > use the type checker to enforce consistent comparison functions between two > different sets which were, say, being merged. I think you can enforce this > using the functor approach provided the Sets came from the same functor > "instantiation". With my words: I understand functors as a way to parametrize a type with a value. They allow you to detect inconsistencies at compile time (e.g. 2 sets parametrized with different "compare" functions). Without functors, as far as I know, you can only test inconsistencies at run time (e.g. by putting all the parameters in a record an check physical equality of the records). > Functors appear to be somewhat similar to templates in C++. Does the functor > approach produce more efficient code as it is partially specialised over the > comparison function? Unfortunately no. Julien Signoles wrote a defunctorizer (works from the source code of the functor): http://www.lri.fr/~signoles/ocamldefun/manual.html Maybe some user manual should tell us more about when to use functors rather than just how to use them. Martin ------------------- 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