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 UAA32268; Sun, 26 Sep 2004 20:56:36 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA28681 for ; Sun, 26 Sep 2004 20:56:35 +0200 (MET DST) Received: from ptb-relay01.plus.net (ptb-relay01.plus.net [212.159.14.212]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i8QIuYml010058 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 26 Sep 2004 20:56:35 +0200 Received: from [80.229.56.224] (helo=chetara) by ptb-relay01.plus.net with esmtp (Exim) id 1CBeCI-000PDE-He for caml-list@inria.fr; Sun, 26 Sep 2004 18:56:34 +0000 From: Jon Harrop To: caml-list Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features Date: Sun, 26 Sep 2004 19:51:52 +0100 User-Agent: KMail/1.6.2 References: <20040925225246.48566.qmail@web53010.mail.yahoo.com> <200409261405.37558.jon@jdh30.plus.com> <1096209379.28613.64.camel@pelican.wigram> In-Reply-To: <1096209379.28613.64.camel@pelican.wigram> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200409261951.52609.jon@jdh30.plus.com> X-Miltered: at concorde with ID 415710E2.001 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 2004:99 hofs:01 val:01 val:01 generic:01 covariance:01 trade-off:01 boils:01 generative:01 inference:01 lacking:01 ocaml:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sunday 26 September 2004 15:36, skaller wrote: > On Sun, 2004-09-26 at 23:05, Jon Harrop wrote: > > If you have HOFs, you > > just write my "sum" function and get on with something more interesting. > > Nope. That only works for a limited class algorithms. > Try a map function.. woops, you can't type it .. :) Yes you can: # let vec_add map2 = map2 ( +. );; val vec_add : ((float -> float -> float) -> 'a) -> 'a = So you can then do: # let list_add = vec_add List.map2;; val list_add : float list -> float list -> float list = I think you're thinking of a function to convert between 'a and 'b container types. This can be achieved in general by folding an insertion function using the fold of the input container and the insertion of the output container. As I've said recently, doing this in the completely generic case buys you nothing but writing *_of or of_* functions does, for example a list_of function which accepts a fold and container of any type: # let cons h t = h::t;; val cons : 'a -> 'a list -> 'a list = # let list_of fold_right c = fold_right cons c [];; val list_of : (('a -> 'a list -> 'a list) -> 'b -> 'c list -> 'd) -> 'b -> 'd = Then you have: # let list_of_array a = list_of Array.fold_right a;; val list_of_array : 'a array -> 'a list = > This is somehow like the covariance problem: things > kind of work for one variable by cheating, but once > you have several it fails. You mean there is a trade-off of functionality between more- and less-capable type systems? > Accumulate can accept a function object argument. > C++ DOES have higher order functions. That statement is so HOF-definition dependent that it boils down to "C++ is Turing complete". > Ocaml run time can also support polymorphic higher > order functions -- but the type system as of > Ocaml 3.04 could not. 3.08 can support them with > the same problem as C++: messy housekeeping > is required -- you have to put them in a record > or class. [This is not so good because records > and variants are generative/nominally typed like C++ classes > .. Ocaml classes are actually algebraic .. LOL!] I don't follow. List.fold_left is a polymorphic HOF that's been around for donkey's years, AFAIK. > Sure but Ocaml offers other advantages such as type inference > lacking in C++ that make code more concise -- as well > as nice scoping constructs, lexical scoping, higher > order functions, variants, and garbage collection. > [Did I miss something .. ? :] Good looking programmers. Cheers, Jon. ------------------- 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