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

[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: 2004-02-04 (03:00) From: Walid Taha Subject: Re: [Caml-list] partial eval question
```
On Mon, 27 Oct 2003, Andrew Lenharth wrote:

|On Mon, Oct 27, 2003 at 03:39:21PM +0000, 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.)
|
|And that's an improvement over
|
|template <int N>
|inline double pow (double x) {
|  return x * pow<N-1>(x);
|}
|template<>
|inline double pow<0> (double x) {
|  return 1.0;
|}
|
|in what way exactly?  (If it doesn't work for you, try
|-O2) :)

http://www.cs.rice.edu/~taha/publications/preprints/2003-12-01.pdf

(Comments are welcome, actually, the paper is undergoing the final
revision).

|The C example relies on a fairly smart compiler to
|do interprocedual analysis.  The C++ example
|only requires the inline keywork be honored, and you
|don't need explicit pow3 pow2, you have pow<3> pow<2>
|pow<any constant>.
|
|Gives a bit more control over code generation.

The draw back with C++ templates, in this case, is that you have to wait
until the C++ code is generate before you know it type checks.  A key goal
of MSP is to ensure that generated code is *always* well-typed.  That
actually has been achieved in the context of a wide-range of type systems.

Walid.

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

--

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

```