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 MAA25074; Mon, 27 Sep 2004 12:50:29 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 MAA24227 for ; Mon, 27 Sep 2004 12:50:28 +0200 (MET DST) Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.202]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i8RAoRdX020332 for ; Mon, 27 Sep 2004 12:50:27 +0200 Received: by mproxy.gmail.com with SMTP id 79so3167644rnk for ; Mon, 27 Sep 2004 03:50:26 -0700 (PDT) Received: by 10.38.171.2 with SMTP id t2mr14608rne; Mon, 27 Sep 2004 03:50:26 -0700 (PDT) Received: by 10.38.75.19 with HTTP; Mon, 27 Sep 2004 03:50:26 -0700 (PDT) Message-ID: <7f8e92aa0409270350ce0eed2@mail.gmail.com> Date: Mon, 27 Sep 2004 13:50:26 +0300 From: Radu Grigore Reply-To: Radu Grigore To: Jon Harrop Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features Cc: caml-list In-Reply-To: <200409270259.43863.jon@jdh30.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <20040925225246.48566.qmail@web53010.mail.yahoo.com> <200409261951.52609.jon@jdh30.plus.com> <7f8e92aa04092613141479823e@mail.gmail.com> <200409270259.43863.jon@jdh30.plus.com> X-Miltered: at nez-perce with ID 4157F073.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 2004:99 generic:01 implemented:01 extlib:01 ocaml:01 ocaml:01 sep:01 iterators:02 iterators:02 wrote:03 library:03 library:03 stl:03 data:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 27 Sep 2004 02:59:43 +0100, Jon Harrop wrote: > What is the difference between a generic function and a function which > dispatches to appropriate specialised functions? For the client of the function there is no difference. For the writter of the function there is a big difference, especially if it has to write the specialized versions. The good news is that the OCaml library gives you those specialized functions (fold) for common data structures like List and Array. The bad news is that you are on your own if you define new data structures that can be viewed as sequences. The meaning of "fold" is "apply this function repeatedly for each element of the data-structure and accumulate the result". I'd like to be able to write this in code _once_ for every data-structure that can be seen as a sequence (i.e. a set of totaly ordered elements). You can do this with iterators. As the article cited by Vasili shows there is an analogue of iterators in functional languages. Another solution is implemented in Extlib. So we are not really talking here about differences between OCaml and C++; we are talking about library design. However, John said that talking about "sequences" means that we are actually artificially limiting a more general concept: shape. But I don't quite understand this idea fully. regards, radu http://rgrig.idilis.ro/ ------------------- 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