Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Functors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-05-02 (10:24)
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
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

Maybe some user manual should tell us more about when to use functors
rather than just how to use them.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: