Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] productivity improvement
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jeffrey Palmer <jeffrey.palmer@a...>
Subject: Re: [Caml-list] Re: Camlp4 optimizations (was: productivity improvement)
On Thursday 17 October 2002 6:55 pm, Alessandro Baretta wrote:
> I'm sorry to have to point out that this is false. The
> template rewriting mechanism knows absolutely nothing about
> typing. You can give the C++ compiler a template it will
> placidly accept, while at the same time giving you all sorts
> or typing errors at template instantiation time. This means
> that if you write a template library in C++ you'll know if
> it is type-correct (with respect to C++ *very weak* typing
> rules) only when you try to use it in some other project.
> This is equivalent to the non-typing of assembly language,
> which yields all sorts of runtime errors to the users. As
> far as C++ templates go, you have to consider as users the
> programmers who will use the template library. Template
> instantiation plays the part of running an assembled program.
>

Hmm. I have two observations:

1) You can't "use" templates without instantiating them, so although 
you're right - template type checking is deferred to instantiation, 
this is by design (a pain, I agree).

2) Template code, during instantiation, has access to the type system. 
You can write conditional template code that will be instantiated only 
if A is a subclass of B, etc. Although the mechanisms used to do this 
are obtuse, it is possible.

> The golden rule of C++: Use classes, not templates.

Interesting. I'd say the opinion has shifted from not using templates to 
using them for almost everything. It seems that, since the introduction 
of the C++ standard library, everyone is building template libraries. 
It's almost as though people have decided that "virtual" is a dirty 
word. ;)

> Once Camlp4 has built the syntax
> tree you can apply any program transformation you care to,
> in order to optimize your program.

I really have to make some time to play with that thing - it really 
sounds amazing.

Oh, and in response to my own earlier question regarding partial 
evaluation and strongly-typed languages, I noticed a post elsewhere on 
the list to a very interesting site:

http://www.cs.rice.edu/~taha/MetaOCaml/

Enjoy!

	- j

-- 
The river is moving.
The blackbird must be flying.

-------------------
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