Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Walid Taha <taha@c...>
Subject: Re: [Caml-list] partial eval question

On Mon, 27 Oct 2003, William Chesters wrote:

|Damien writes:
| > Multi-Stage Programming is your friend...
| > <http://www.cs.rice.edu/~taha/MSP/>
| > 
| > let rec pow n = .< 
| > 	.~(match n with
| > 		| 1 -> .< fun x -> x >.
| > 		| n -> .< fun x -> x * .~(pow (n-1)) x>.
| > 	)
| > >.
| > 
| > (pow 3) get reduced into .<fun x -> x*x*x>.
|
|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.)

Two reasons:  1) MSP is finer grained (you usually DON'T want to unroll
all loops), and 2) you can do it at runtime (it's not limited to
compile-time specialization).  Those two simple reasons have a huge impact
when you are building bigger and more complex software systems.

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

Why is MSP labour intensive?  More importantly, why do you think it is
error-prone?

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

What kinds do you have in mind?

MSP's primary target users are indeed builders of code generators, but you 
seem to suggest that that somehow needs to be limited to an elite group of 
"generator writers"...  That's exactly what MSP is supposed to help Joe 
Programmer avoid.

Walid.

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