Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: -- (:)
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,
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: