* [Caml-list] C++ templates to OCaml
@ 2005-06-19 6:53 Jonathan Roewen
2005-06-19 13:17 ` Jacques Carette
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Jonathan Roewen @ 2005-06-19 6:53 UTC (permalink / raw)
To: caml-list
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?
Jonathan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] C++ templates to OCaml
2005-06-19 6:53 [Caml-list] C++ templates to OCaml Jonathan Roewen
@ 2005-06-19 13:17 ` Jacques Carette
2005-06-19 18:05 ` padiolea
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Jacques Carette @ 2005-06-19 13:17 UTC (permalink / raw)
To: Jonathan Roewen, caml-list
Jonathan Roewen <jonathan.roewen@gmail.com> wrote:
>
> What's the best way to imitate C++ templates in OCaml?
<plug>
I have been quite successful at doing C++ template-like things in MetaOCaml.
In fact, using Functors and Modules judisciously, it is possible to hide all of the code-generation aspects and write
quite straightforward code that can be instantiated in many different ways.
An earlier version of this work (joint with Oleg Kiselyov) is available at
http://www.cas.mcmaster.ca/~carette/metamonads/, and has been accepted at GPCE 2005.
</plug>
Thanks for asking ;-)
Jacques
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] C++ templates to OCaml
2005-06-19 6:53 [Caml-list] C++ templates to OCaml Jonathan Roewen
2005-06-19 13:17 ` Jacques Carette
@ 2005-06-19 18:05 ` padiolea
[not found] ` <1119175572.7402.1.camel@titania>
2005-06-20 2:53 ` Brian Hurt
3 siblings, 0 replies; 6+ messages in thread
From: padiolea @ 2005-06-19 18:05 UTC (permalink / raw)
To: Jonathan Roewen; +Cc: caml-list
> Hi,
>
> What's the best way to imitate C++ templates in OCaml?
Well, simply use polymorphic types and functions.
> 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?
read the ocaml manual, or code in list.ml for instance in the
ocaml standard library.
> Jonathan
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] C++ templates to OCaml
[not found] ` <1119175572.7402.1.camel@titania>
@ 2005-06-19 21:32 ` Jonathan Roewen
2005-06-19 22:34 ` Benjamin Geer
0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Roewen @ 2005-06-19 21:32 UTC (permalink / raw)
To: caml-list
> I'd venture that you probably want functions and/or modules. Without any
> detail, though, it's difficult to say more.
Ok. Well, I want to rewrite the antigrain geometry library in OCaml
(www.antigrain.com). They make extensive use of chaining together
template classes. So, I'd use a module to represent each template
class, and polymorphic functions?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] C++ templates to OCaml
2005-06-19 21:32 ` Jonathan Roewen
@ 2005-06-19 22:34 ` Benjamin Geer
0 siblings, 0 replies; 6+ messages in thread
From: Benjamin Geer @ 2005-06-19 22:34 UTC (permalink / raw)
To: Jonathan Roewen; +Cc: caml-list
On 19/06/05, Jonathan Roewen <jonathan.roewen@gmail.com> wrote:
> So, I'd use a module to represent each template
> class, and polymorphic functions?
The book _Developing Applications with Objective Caml_ gives a good
comparison of modules, functors and classes, which might help you find
the best approach for your library. See chapters 14, 15 and 16:
http://caml.inria.fr/pub/docs/oreilly-book/html/index.html
Ben
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] C++ templates to OCaml
2005-06-19 6:53 [Caml-list] C++ templates to OCaml Jonathan Roewen
` (2 preceding siblings ...)
[not found] ` <1119175572.7402.1.camel@titania>
@ 2005-06-20 2:53 ` Brian Hurt
3 siblings, 0 replies; 6+ messages in thread
From: Brian Hurt @ 2005-06-20 2:53 UTC (permalink / raw)
To: Jonathan Roewen; +Cc: caml-list
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++).
Brian
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-06-20 2:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-19 6:53 [Caml-list] C++ templates to OCaml Jonathan Roewen
2005-06-19 13:17 ` Jacques Carette
2005-06-19 18:05 ` padiolea
[not found] ` <1119175572.7402.1.camel@titania>
2005-06-19 21:32 ` Jonathan Roewen
2005-06-19 22:34 ` Benjamin Geer
2005-06-20 2:53 ` Brian Hurt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox