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] partial eval question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-10-27 (19:18)
From: Yann Regis-Gianas <yann.regisgianas@f...>
Subject: Re: [Caml-list] partial eval question
William Chesters wrote :
> And that's an improvement over
>     double pow(double x, int n) {
>       double it = 1;
>       while (--n >= 0) it *= x;
>       return it;
>     }
>     double pow3(double x, int n) {
>       return pow(x, 3);
>     }
> in what way exactly?  (If it doesn't work for you, try
> -funroll-all-loops.)
> For these kinds of purposes, Multi-Stage Programming is a very
> labour-intensive and error-prone way of doing what mainstream
> compilers will do for you already.  

	I agree with you that constant folding, inlining and unrolling are well known 
by common compilers. However, when you want to _control_  these 
optimisations, this is more difficult with standard optimizers since they are 
black-boxes. For example, the benefit of these optimizations is linked with 
the size of code, the processor type but also with the values of data (think 
of the sparse matrix example). All these parameters cannot be managed by a 
low level compiler optimizer. 

	In MetaOCaml, the general process of multi-stage evaluation enables the 
user-control of optimization simply :

let k = eval_processor_capabilities ()

let rec pow n = function 
                | 1 -> .< fun x -> x >.
                | n when n < k -> .< fun x  -> x * .~(pow (n-1)) x>.
		| n -> .< fun x -> x *. (.! (pow (n-1)) x >.

> Maybe it has useful applications
> in e.g. generation of numerical codes, where inlining, unrolling,
> "templatization" and partial evaluation are not enough because major
> structural transformations are required.  But then, maybe
> sophisticated jobs like that are always going to be easiest done with
> special-purpose code generators?

	By adding the multi-stage evaluation into a programming language, we obtain 
one general,  transparent and simple tool. Why should we develop or learn the 
usage of many special-purpose optimizers ? Yes, some work has to be done to 
enhance its user-friendliness but, in my opinion, this feature can be 
relevant in many daily programming situations (not only optimization). There 
are some papers about that, for example :

"Accomplishments and Research Challenges in Meta-programming". 
Tim Sheard.

Yann Regis-Gianas.

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