From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA05442; Wed, 3 Jul 2002 10:43:22 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA05539 for caml-list@pauillac.inria.fr; Wed, 3 Jul 2002 10:43:22 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA05127 for ; Wed, 3 Jul 2002 10:37:00 +0200 (MET DST) Received: from main.gmane.org (main.gmane.org [80.91.224.249]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g638axH00555 for ; Wed, 3 Jul 2002 10:37:00 +0200 (MET DST) Received: from list by main.gmane.org with local (Exim 3.33 #1 (Debian)) id 17Pfcf-0005lH-00 for ; Wed, 03 Jul 2002 10:36:25 +0200 To: caml-list@inria.fr X-Injected-Via-Gmane: http://gmane.org/ Received: from news by main.gmane.org with local (Exim 3.33 #1 (Debian)) id 17Pfcf-0005l9-00 for ; Wed, 03 Jul 2002 10:36:25 +0200 Path: not-for-mail From: Ketanu Newsgroups: gmane.comp.lang.caml.inria Subject: [Caml-list] Re: generic programming Date: Wed, 03 Jul 2002 10:37:41 +0200 Organization: (none) Message-ID: <87r8il436y.fsf@ketanu.dyndns.org> References: <200207030246.WAA28665@dewberry.cc.columbia.edu> NNTP-Posting-Host: amontpellier-203-1-1-139.abo.wanadoo.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1025685385 22142 80.13.70.139 (3 Jul 2002 08:36:25 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 3 Jul 2002 08:36:25 +0000 (UTC) User-Agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2 (i386-debian-linux-gnu) Cancel-Lock: sha1:aZ77Nj1TwIg0uNuddFUYoTL0/eY= Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Oleg 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 need). You may also write a function pearson_correlation with the four arguments set1 set2 iter1 iter2, with types set1:'a set2:'b 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 iteration). Hope it helps ! -- Ketanu - 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