<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/10/749531e3b7c66d1e814447e320033178"
  from="William Chesters &lt;williamc@p...&gt;"
  author="William Chesters"
  date="2003-10-27T15:37:36"
  subject="Re: [Caml-list] partial eval question"
  prev="2003/10/5c56916575fdd0744175f41cd4839676"
  next="2003/10/74ccb9c25328fbf9839b7e723ba013ee"
  prev-in-thread="2003/10/42e4a058f34baa9bc4a7f09a01c2fb56"
  next-in-thread="2004/02/40c8a56a41ad341968457f98c05e781e"
  prev-thread="2003/10/8079542ef4415111bf59cd27c0f9ab57"
  next-thread="2003/10/7acd408e746382c8e686db8ca031c848"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] partial eval question">
<msg 
  url="2003/10/de29dc29683545ed76beb0400f4751ec"
  from="Ben Kavanagh &lt;kavabean@l...&gt;"
  author="Ben Kavanagh"
  date="2003-10-27T01:42:24"
  subject="[Caml-list] partial eval question">
<msg 
  url="2004/02/9135da4880860aff7ee6bd2862347f71"
  from="Walid Taha &lt;taha@c...&gt;"
  author="Walid Taha"
  date="2004-02-04T02:51:13"
  subject="Re: [Caml-list] partial eval question">
<msg 
  url="2004/02/c9aa99c7ce1da5f86ed1c84a68d5577b"
  from="Ben Kavanagh &lt;kavabean@l...&gt;"
  author="Ben Kavanagh"
  date="2004-02-04T10:27:05"
  subject="RE: [Caml-list] partial eval question">
</msg>
<msg 
  url="2004/02/ab28e6d5251dbb35de26f4800a7648dd"
  from="Ben Kavanagh &lt;kavabean@l...&gt;"
  author="Ben Kavanagh"
  date="2004-02-04T10:32:54"
  subject="RE: [Caml-list] partial eval question">
<msg 
  url="2004/02/3a9f4f3f0fb6f94213b4b497d4d87bae"
  from="Walid Taha &lt;taha@c...&gt;"
  author="Walid Taha"
  date="2004-02-05T21:12:38"
  subject="RE: [Caml-list] partial eval question">
</msg>
</msg>
</msg>
<msg 
  url="2003/10/42e4a058f34baa9bc4a7f09a01c2fb56"
  from="Damien &lt;Damien.Pous@e...&gt;"
  author="Damien"
  date="2003-10-27T07:12:59"
  subject="Re: [Caml-list] partial eval question">
<msg 
  url="2003/10/749531e3b7c66d1e814447e320033178"
  from="William Chesters &lt;williamc@p...&gt;"
  author="William Chesters"
  date="2003-10-27T15:37:36"
  subject="Re: [Caml-list] partial eval question">
<msg 
  url="2004/02/40c8a56a41ad341968457f98c05e781e"
  from="Walid Taha &lt;taha@c...&gt;"
  author="Walid Taha"
  date="2004-02-04T02:57:05"
  subject="Re: [Caml-list] partial eval question">
</msg>
<msg 
  url="2003/10/630a4b8fb712e5f64fd00f8517c2efb1"
  from="Andrew Lenharth &lt;andrewl@d...&gt;"
  author="Andrew Lenharth"
  date="2003-10-27T18:50:37"
  subject="Re: [Caml-list] partial eval question">
<msg 
  url="2004/02/a16f564331f7ac87203f997832197d47"
  from="Walid Taha &lt;taha@c...&gt;"
  author="Walid Taha"
  date="2004-02-04T03:00:08"
  subject="Re: [Caml-list] partial eval question">
<msg 
  url="2004/02/62aff25824ac1dc4ddf6439cc95b8e2c"
  from="Andrew Lenharth &lt;alenhart@c...&gt;"
  author="Andrew Lenharth"
  date="2004-02-04T06:23:08"
  subject="Re: [Caml-list] partial eval question">
<msg 
  url="2004/02/ab4a9a7eeb231ae65620cc62433710d4"
  from="Walid Taha &lt;taha@c...&gt;"
  author="Walid Taha"
  date="2004-02-05T21:29:51"
  subject="Re: [Caml-list] partial eval question">
</msg>
</msg>
</msg>
<msg 
  url="2003/10/4240dba8e9df9f12e8085e87299a5d53"
  from="William Chesters &lt;williamc@p...&gt;"
  author="William Chesters"
  date="2003-10-27T19:10:12"
  subject="Re: [Caml-list] partial eval question">
<msg 
  url="2003/10/5f2fdaad333177c7d6a2b21daa0be41d"
  from="Jacques Carette &lt;carette@m...&gt;"
  author="Jacques Carette"
  date="2003-10-27T20:08:39"
  subject="RE: [Caml-list] partial eval question">
<msg 
  url="2004/02/fbf18488391fa9746efc5d2a4bef8477"
  from="Walid Taha &lt;taha@c...&gt;"
  author="Walid Taha"
  date="2004-02-04T03:04:02"
  subject="RE: [Caml-list] partial eval question">
</msg>
</msg>
<msg 
  url="2003/10/c5624fb84802867145896d6186f42066"
  from="Andrew Lenharth &lt;andrewl@d...&gt;"
  author="Andrew Lenharth"
  date="2003-10-27T22:11:26"
  subject="Re: [Caml-list] partial eval question">
</msg>
</msg>
</msg>
<msg 
  url="2003/10/a7723a0e7c90bd6cbf8e4e5e50cc4401"
  from="Yann Regis-Gianas &lt;yann.regisgianas@f...&gt;"
  author="Yann Regis-Gianas"
  date="2003-10-27T19:18:48"
  subject="Re: [Caml-list] partial eval question">
<msg 
  url="2003/10/5b5b69bb4359248a36d2c5d540be38c3"
  from="William Chesters &lt;williamc@p...&gt;"
  author="William Chesters"
  date="2003-10-28T10:43:30"
  subject="Re: [Caml-list] partial eval question">
<msg 
  url="2004/02/861c8dd1fe70d0ffecfa0a33b820271e"
  from="Walid Taha &lt;taha@c...&gt;"
  author="Walid Taha"
  date="2004-02-04T02:22:58"
  subject="Re: [Caml-list] partial eval question">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/10/36fc484e0287ec54175420cdd6ec261b"
  from="Dmitry Lomov &lt;Dmitry.Lomov@i...&gt;"
  author="Dmitry Lomov"
  date="2003-10-28T15:17:02"
  subject="Re: [Caml-list] partial eval question">
</msg>
</msg>
<msg 
  url="2003/10/911861d0f0fa5c5495de5216bbf14cad"
  from="Vincent Balat [prof Moggi team] &lt;balat@d...&gt;"
  author="Vincent Balat [prof Moggi team]"
  date="2003-10-27T15:21:53"
  subject="Re: [Caml-list] partial eval question">
</msg>
</msg>
</thread>

<contents>
Damien writes:
 &gt; Multi-Stage Programming is your friend...
 &gt; &lt;http://www.cs.rice.edu/~taha/MSP/&gt;
 &gt; 
 &gt; There are two ML implementations :
 &gt; Ocaml : MetaOCaml &lt;http://www.cs.rice.edu/~taha/MetaOCaml/&gt;
 &gt; SML : MetaML &lt;http://www.cse.ogi.edu/PacSoft/projects/metaml/&gt;
 &gt; 
 &gt; 
 &gt; let rec pow n = .&lt; 
 &gt; 	.~(match n with
 &gt; 		| 1 -&gt; .&lt; fun x -&gt; x &gt;.
 &gt; 		| n -&gt; .&lt; fun x -&gt; x * .~(pow (n-1)) x&gt;.
 &gt; 	)
 &gt; &gt;.
 &gt; 
 &gt; (pow 3) get reduced into .&lt;fun x -&gt; x*x*x&gt;.

And that's an improvement over

    double pow(double x, int n) {
      double it = 1;
      while (--n &gt;= 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.  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?

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

</contents>

</message>

