From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA17282; Fri, 18 Oct 2002 01:45:08 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA16433 for ; Fri, 18 Oct 2002 01:45:07 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com ([62.211.4.136]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9HNiu526312 for ; Fri, 18 Oct 2002 01:45:02 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 87C8027250; Fri, 18 Oct 2002 01:55:36 +0200 (CEST) Message-ID: <3DAF4DF8.707@baretta.com> Date: Fri, 18 Oct 2002 01:55:36 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: it, en MIME-Version: 1.0 To: Jeffrey Palmer , Ocaml Subject: Re: [Caml-list] Re: Camlp4 optimizations (was: productivity improvement) References: <200210171637.15448.jeffrey.palmer@acm.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Jeffrey Palmer wrote: > However, the (obvious) problem with this approach, from a C++ > perspective, is that it is not supported by the language. This stuff > was basically "discovered", rather than designed, and if you've ever > tried to use these techniques, this becomes VERY clear. The syntax is a > disaster. An in-language mechanism for this type of macro expansion (a > la lisp/scheme macros) would simplify this immensely. > > Is this approach implementable in ocaml? The C++ template mechanism has > complete access to the C++ type system, which makes it significantly > more useful than the standard preprocessor. I seem to remember an > earlier posting (today) indicating that this type information isn't > available in ocamlp4. 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. Besides, what kind of access to the type system can a *generic* program have? If it depended on specific features of specific types it would no longer be generic, would it not? The golden rule of C : Use functions, not macros. The golden rule of C++: Use classes, not templates. The Java developers knew both rules. They made a mess anyway. > Does anyone know of any strongly-typed languages where this type of > macro expansion/partial evaluation is available? (I seem to remember > GHC providing a hook mechanism for term rewriting during optimization, > but I don't think that's quite the same...) Ocaml. Macro expansion == Syntax extension. Macro processor == Camlp4. Keep in mind that Camlp4 builds the complete abstract syntax tree of an ocaml program you parse with it. It later feeds the tree to the compiler. Once Camlp4 has built the syntax tree you can apply any program transformation you care to, in order to optimize your program. Of course, before applying such "program-rewriting-at-compile-time" techniques, you should prove them to be correct. Alex ------------------- 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