On Mon, May 2, 2011 at 9:40 PM, gex <[email protected]> wrote:
> When using modules and functors, I still have to prefix each function
> call with a concrete implementation module. Instead I want to prefix
> it with a general signature (like collection) so that I can quickly
> exchange the underlying implementation.

You can alias modules.  Say you have two different collection
implementations, ListCollection and ArrayCollection.  In code that
uses these, you can write:

module Collection = ListCollection
Collection.insert x y;
Collection.remove z y (* etc. *)

When you want to replace the ListCollection with an ArrayCollection,
you need only change the first line:

module Collection = ArrayCollection

and the rest of your code will use ArrayCollection instead of ListCollection.

What you *can't* do is have different collections use different
underlying implementations, but access them all with the same
interface (unless you create some sort of wrapper module but then
you're recreating objects).  That can only be done with object systems
or typeclass systems (like in Haskell and Mercury).

HTH.

- Chris

-- 
You received this message because you are subscribed to the Google Groups 
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html

Reply via email to