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 GAA13782; Mon, 27 Sep 2004 06:48:11 +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 GAA13243 for ; Mon, 27 Sep 2004 06:48:09 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i8R4m7bk007897 for ; Mon, 27 Sep 2004 06:48:08 +0200 Received: from [192.168.1.200] (ppp202-133.lns1.syd3.internode.on.net [203.122.202.133]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i8R4m34Y073764; Mon, 27 Sep 2004 14:18:05 +0930 (CST) Subject: Re: [Caml-list] C++ STL and template features compared with OCaml parametric polymorphism and OO features From: skaller Reply-To: skaller@users.sourceforge.net To: Jon Harrop Cc: caml-list In-Reply-To: <200409270259.43863.jon@jdh30.plus.com> References: <20040925225246.48566.qmail@web53010.mail.yahoo.com> <200409261951.52609.jon@jdh30.plus.com> <7f8e92aa04092613141479823e@mail.gmail.com> <200409270259.43863.jon@jdh30.plus.com> Content-Type: text/plain Message-Id: <1096260483.28613.426.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 27 Sep 2004 14:48:03 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41579B87.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 sourceforge:01 2004:99 recursion:01 camlp:01 9660:01 glebe:01 ocaml:01 ocaml:01 variants:01 int:01 int:01 nsw:01 exists:01 snail:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 2004-09-27 at 11:59, Jon Harrop wrote: > In practice, I'm all for > aggressive factoring but I can't see what we're factoring here... Sure you can. Consider: type 'a F = A | B of 'a | C of 'a * 'a * int Can you write a map function for this? Of course you can! What about: type 'a F = A of int | C of 'a * int | X of 'a F * 'a Yes, of course you can! Its obvious how to do it! There *exists* a universal algorithm in your head for writing map functions. But this pattern cannot be encoded in Ocaml as an HOF: map: 'a 'F -> ('a -> 'b) -> 'b 'F You can do this provided you have only types built from variants, tuples, and recursion (no function types). In fact you could probably write this function in camlp4 from the definition of each type for which you need a map. -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- 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