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] generic programming
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-07-08 (15:49)
From: John Max Skaller <skaller@o...>
Subject: Re: [Caml-list] Re: generic programming
Francois Pottier wrote:

>On Sat, Jul 06, 2002 at 12:05:30AM +0100, Dave Berry wrote:
>>>An iterator is a function that returns a function which maintains a
>>>piece of internal state. 
>>But can you compile it down to a single increment instruction on a pointer
>>(for an iterator over an array)?

>Some ML compilers perform some of these optimizations. O'Caml performs none,
>as far as I know; they are tricky to implement, especially in combination.
>I'd be curious to see how C++ achieves this.
Simple: templates use 'textual substitution'. An array iterator IS a 
So there is no analysis to do. They're also good at optimising classes
with a single data member (int, pointer, etc).

The one that C++ compilers find hard is to see that the instantiations:

    copy<int*,int*,int*> ...
    copy<unisgned int*,unsigned int*, unsigned int*>

can share the same implementation: programmers usually suppress code bloat
on template instantiation using wrapping tricks, knowing that compilers
aren't yet very smart at it.

John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.

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