From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id ED2AFBBFB for ; Mon, 20 Jun 2005 04:49:08 +0200 (CEST) Received: from conn.mc.mpls.visi.com (conn.mc.mpls.visi.com [208.42.156.2]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j5K2n8R1020243 for ; Mon, 20 Jun 2005 04:49:08 +0200 Received: from [192.168.42.2] (bhurt.dsl.visi.com [208.42.141.66]) by conn.mc.mpls.visi.com (Postfix) with ESMTP id 2801C81CC; Sun, 19 Jun 2005 21:49:07 -0500 (CDT) Date: Sun, 19 Jun 2005 21:53:31 -0500 (CDT) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: Jonathan Roewen Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] C++ templates to OCaml In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at concorde with ID 42B62EA4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 ocaml:01 pcaml:01 2005,:98 wrote:01 imho:01 rewrite:01 functions:01 objects:02 types:02 types:02 programming:03 brian:03 brian:03 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: On Sun, 19 Jun 2005, Jonathan Roewen wrote: > Hi, > > What's the best way to imitate C++ templates in OCaml? I have some > code that makes extensive use of templates that I want to rewrite in > OCaml, and using record types and functions is getting messy, and a > lot more convoluted than the C++ code. > > Are objects the way to go here? And if so, can someone give me a > simple example of how this would work? 95-99% of the uses of templates are easily replaced with either universal types (so List becomes 'a list) or with templates (see Set and Map). The remainder is template meta programming, for which you probably need pcaml, or I'd recommend rethinking the approach (template metaprogramming is, IMHO, one of things wrong with C++). Brian