<?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/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"
  prev="2003/10/a76f7765af24e57fcc433c6000107918"
  next="2003/10/5c56916575fdd0744175f41cd4839676"
  prev-in-thread="2003/10/36fc484e0287ec54175420cdd6ec261b"
  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>

I am working on a "type-directed" partial evaluator for OCaml.
I did an implementation a few years ago with Olivier Danvy
(see http://www.pps.jussieu.fr/~balat/publications/balat-danvy.pdf)

But it is still*experimental*:
 - only a small subset on ocaml
 - need a modified version of ocaml with a "call/cc" operator

ex:
# let rec power mul one x n = 
      if n=0 then one 
      else (mul x (power mul one x (n-1)));;  
      (* We close by mul and one because the function to be
         normalized must be mostly polymorphic *)
val power : ('a -&gt; 'b -&gt; 'b) -&gt; 'b -&gt; 'a -&gt; int -&gt; 'b = &lt;fun&gt;

# let power3 mul one x = power mul one x 3;;
val power3 : ('a -&gt; 'b -&gt; 'b) -&gt; 'b -&gt; 'a -&gt; 'b = &lt;fun&gt;

# normalize "power3";;
- : unit = ()
(* Now the function power3 is normalized *)

(* You can print the normalized code by: *)
# normalize_nf "power3";;
- : NormalForms.computation =
(fun v7 v8 v9 -&gt;
 let v10 = v7 v9 in
 let v11 = v10 v8 in
 let v12 = v7 v9 in
 let v13 = v12 v11 in
 let v14 = v7 v9 in
 let v15 = v14 v13 in
 v15)

It is not available on the web  any more (it was for ocaml 1.05) but I
can send it to you if you are interested.

I'm planning to update  it and to try to extend it  to a larger subset
of ocaml.  There are still a  lot of opened questions  to solve before
having it included in ocaml...

Otherwise,  as  pointed  by  Damien  Pous,  you can  have  a  look  at
MetaOCaml, which is  a multi-level language based on  ocaml, that is a
language  that   allows  you   to  manipulate  source   code  (program
generation).

Vincent Balat

---- Ben Kavanagh écrit :
 &gt; 
 &gt; Say I have a function such as pow defined as
 &gt; 
 &gt; let pow n x = 
 &gt;     let rec pow_iter (n1, x1, p1) = 
 &gt;         if (n1 = 0) then p1 
 &gt;         else if (n1 mod 2 = 0) 
 &gt; 		 then pow_iter(n1/2, x1*x1, p1) 
 &gt;              else pow_iter(n1-1, x1, p1*x1)
 &gt;     in pow_iter(n, x, 1);;
 &gt; 
 &gt; and I say 
 &gt; 
 &gt; let pow2 = pow 2
 &gt; 
 &gt; Are there any ML implementations that would automatically perform
 &gt; partial evaluation to create pow2 instead of using closures, possibly
 &gt; unfolding the pow_iter call? Would Caml ever have this capability?
 &gt; 
 &gt; Ben
 &gt; 
 &gt; 
 &gt; -------------------
 &gt; To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
 &gt; Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
 &gt; Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
 &gt; 

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

