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 BAA20402; Fri, 19 Jul 2002 01:13:10 +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 BAA20398 for ; Fri, 19 Jul 2002 01:13:10 +0200 (MET DST) Received: from dewberry.cc.columbia.edu (dewberry.cc.columbia.edu [128.59.59.68]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6IND8H12218 for ; Fri, 19 Jul 2002 01:13:09 +0200 (MET DST) Received: from there (tw304h3.cpmc.columbia.edu [156.111.84.180]) by dewberry.cc.columbia.edu (8.9.3/8.9.3) with SMTP id TAA19905 for ; Thu, 18 Jul 2002 19:13:07 -0400 (EDT) Message-Id: <200207182313.TAA19905@dewberry.cc.columbia.edu> Content-Type: text/plain; charset="iso-8859-1" From: Oleg To: "caml-list" Subject: Re: [Caml-list] productivity improvement Date: Thu, 18 Jul 2002 19:14:06 -0400 X-Mailer: KMail [version 1.3.2] References: <20020716172916.4903.qmail@web10702.mail.yahoo.com> In-Reply-To: <20020716172916.4903.qmail@web10702.mail.yahoo.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tuesday 16 July 2002 01:29 pm, Shannon --jj Behrens wrote: > Wow, that's an impressive piece of C++!!! C++ never > seems to stop surprising me! Nonetheless, I feel the > OCAML version is infinitely more readable. > > Best Regards, > -jj [...] I'd say, to a person equally familiar with O'Caml and C++, the readability ratio is less than 2 [1] The readability of compiler messages is a whole different story: G++ gives horrible messages when templates, or, god forbid, STL errors are present [2] However, the C++ version looks more "extensible" to me: Suppose that in a while, you decide that you want your "node" to be not only Leaf or Unop or Binop, but also Triop: type 'a node = Leaf of 'a | Unop of ('a->'a) * 'a node | Binop of ('a * 'a -> 'a) * 'a node * 'a node | Triop of ('a * 'a * 'a -> 'a) * 'a node * 'a node * 'a node;; You will need to modify the original node type and function "eval" by adding an extra pattern to "match" statement, and then recompile everying that depends on it. At the same time, with C++ the type of node remains the same. You just need to derive a new class from it: template struct triop : public node { T (*fun)(T, T, T); node &n1; node &n2; node &n3 T eval() { return fun(n1.eval(), n2.eval(), n3.eval); } triop (T (*f)(T, T, T), node& N1, node& N2, node& N3) : fun(f), n1(N1), n2(N2), n3(N3) {} }; Recompiling isn't necessary. In fact, "old code" may call "new code" if you happen to pass it a node that happens to be a triop. Oleg P.S. Having read the CalTech tutorial and chapters 1-4 & 14 of the O'Reilly book, and having gotten some experience with O'Caml, I'm running low on motivation right now. Please give me examples of what's hard/awkward/impossible in C++, but relatively easy in O'Caml, if any (I have only finite time, so 50 KLOC Coq is not a good example :) P.P.S. My primary interest is statistical AI (artificial neural networks). I haven't found any relevant libraries or applications in SML or O'Caml. That is a bit discouraging. [1] And the example was hand-picked! [2] If one doesn't want "ad hoc" genericity, templates aren't necessary, of course. ------------------- 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