[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Martin Jambon <martin_jambon@e...> |
| Subject: | Re: [Caml-list] Functors |
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