English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] C++ templates to OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-06-20 (02:49)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] C++ templates to OCaml

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<T> 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++).