On May 3, 3:40 am, gex <[email protected]> wrote:
> Hi,
>
> I am a programmer coming from OOP. When using ocaml (here in my
> company, we do not use the Objective part, i.e. no objects/classes) I
> wonder how to make implementations exchangeable.

Well, the programming paradigm (OOP, imperative, functional...) has
nothing to do with the ability of separate interface from
implementation.
For example C is not an OO language, but you have .h files and .c
files.


As in C, you have implementation file .ml and an interface file .mli .
When you write only the .ml file, ocaml treats everything in the file
as public.


> Example:
> I want a collection. The implementation should be exchangeable without
> changing the client code.
>
> How to do that (without using classes and objects)?

The simplest way to do that is create a collection.mli in which you
specify the interface:

type 'a collection

val empty : 'a collection

val insert : 'a collection -> 'a -> 'a collection
val remove : 'a collection -> 'a -> 'a collection
...

Then you can link your code with the implementation that better suits
your needs.

O ( n )

-- 
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