English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-07-03 (08:43)
From: Ketanu <ketanu@w...>
Subject: [Caml-list] Re: generic programming
Oleg <oleg_inconnu@myrealbox.com> writes:

> Hi
> Is generic programming possible with O'Caml? Suppose I want to find the
> Pearson correlation between two sets of real numbers represented as sets,
> arrays, big_arrays, maps, stacks, queues or lists. Is it possible to have
> one piece of code that handles all of these containers, a generic function
> of some sort? (Iteration is all that is necessary in the Pearson
> correlation example)

Sure it is possible ! You should embed all these containers into either
objects or modules whith homogenous interface suitable for your algorithm,
and then code thge appropriate functor or object which will provide the
algorithm itself.

You may also build streams on the top of your structures and implement
algorithm for strams (if this is suitable with the kind of iteration you

You may also write a function pearson_correlation with the four arguments
set1 set2 iter1 iter2, with types

iter1:'a -> int -> float
iter2:'b -> int -> float

where the iter1,2 functions must provide iteration over the containers
set1,2 (thus, the types for iter1,2 mas need to be adapted to your

Hope it helps !
Ketanu <katanu@wanadoo.fr> - RSA PGP Key ID: 0x20D90C12

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