caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Ben Kavanagh" <kavabean@lmi.net>
To: "'Walid Taha'" <taha@cs.rice.edu>
Cc: <caml-list@inria.fr>
Subject: RE: [Caml-list] partial eval question
Date: Wed, 4 Feb 2004 10:32:25 -0000	[thread overview]
Message-ID: <000b01c3eb0a$356074e0$b1c92952@Archimedes> (raw)
In-Reply-To: <Pine.LNX.4.44.0402032046400.17089-100000@boromir.cs.rice.edu>

Walid, 

Thanks much for your response. I was aware of MetaOCaml's ability to
stage this computation and I have downloaded/run many of your
benchmarks. My question was more if anyone had an implementation where
normal partial application (normal in ML's syntax) led to partial
evaluation. It turns out that there was an implementation of this,
namely Mark Leone/Peter Lee's Fabius compiler, which, unfortunately, has
never been made available publicly. 

http://portal.acm.org/citation.cfm?id=231407&dl=ACM&coll=portal&CFID=111
11111&CFTOKEN=2222222
http://portal.acm.org/citation.cfm?id=289144&dl=ACM&coll=portal

Such a coarse grained approach to code generation in a program is not
necessarily ideal for all purposes, a point you touch on in a later mail
to the Caml list in your statement about loop unrolling. It does seem,
though, that a useful syntax shortcut that made this direct
partial-application -> partial-evaluation mapping available in the
manner of Lee/Leone could be useful in Caml, and maybe even more
appropriately, MetaOCaml. 

Does this make sense?

Ben




------------------------------------------------------------------------
--------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com


-----Original Message-----
From: Walid Taha [mailto:taha@cs.rice.edu] 
Sent: Wednesday, February 04, 2004 2:51 AM
To: Ben Kavanagh
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] partial eval question


Hi Ben,

Below is a MetaOCaml (www.metaocaml.org) program that does what you were
asking for.  

----- begin ben.ml

Trx.init_times (* Initialize MetaOCaml timer library *)

(* Here's Ben's original code *)

let pow n x =

  let rec pow_iter (n1, x1, p1) =

    if (n1 = 0) then 
      p1                                                         
    else if (n1 mod 2 = 0) then 
      pow_iter(n1/2, x1*x1, p1)                                     
    else pow_iter(n1-1, x1, p1*x1)

  in pow_iter(n, x, 1);;

 

let pow2 = pow 2

(* Here's a staged version of Ben's code *)

let pow' n x =

  let rec pow_iter (n1, x1, p1) =

    if (n1 = 0) then 
      p1                                                         
    else if (n1 mod 2 = 0) then 
      pow_iter(n1/2, .<.~x1 * .~x1>., p1)

    else pow_iter(n1-1, x1, .<.~p1 * .~x1>.)

  in pow_iter(n, x, .<1>.);;

let pow2 = pow' 2

(* Here's some code to get some timings *)

                                          
let unstagedRunning = 
  Trx.timenew "unstaged running"(fun () -> pow 5 3)

let stage1Running =
  Trx.timenew "stage 1 running" (fun () -> .<fun x-> .~(pow' 5 .<x>.)>.)

let compiling = Trx.timenew "compiling" (fun () -> .! stage1Running)

let stage2Running = Trx.timenew "stage 2 running" (fun () -> (compiling 
3))

let baseline = Trx.timenew "baseline" (fun () -> ())

(* Print all the timings *)

let _ = Trx.print_times ()
                                           
(* Outpout of timer:
__ unstaged running ______ 2097152x avg= 7.929525E-04 msec
__ stage 1 running ________ 262144x avg= 7.248323E-03 msec
__ compiling ________________ 8192x avg= 2.320860E-01 msec
__ stage 2 running ______ 16777216x avg= 1.123075E-04 msec
__ baseline _____________ 33554432x avg= 3.921819E-05 msec
*)

--- end ben.ml

Walid.

On Mon, 27 Oct 2003, Ben Kavanagh wrote:

|
|Say I have a function such as pow defined as
|
|let pow n x = 
|    let rec pow_iter (n1, x1, p1) = 
|        if (n1 = 0) then p1 
|        else if (n1 mod 2 = 0) 
|		 then pow_iter(n1/2, x1*x1, p1) 
|             else pow_iter(n1-1, x1, p1*x1)
|    in pow_iter(n, x, 1);;
|
|and I say 
|
|let pow2 = pow 2
|
|Are there any ML implementations that would automatically perform
|partial evaluation to create pow2 instead of using closures, possibly
|unfolding the pow_iter call? Would Caml ever have this capability?
|
|Ben
|
|
|-------------------
|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


  parent reply	other threads:[~2004-02-04 10:32 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-27  1:41 Ben Kavanagh
2003-10-27  7:14 ` Damien
2003-10-27 15:39   ` William Chesters
2003-10-27 18:50     ` Andrew Lenharth
2003-10-27 19:12       ` William Chesters
2003-10-27 20:08         ` Jacques Carette
2004-02-04  3:03           ` Walid Taha
2003-10-27 22:11         ` Andrew Lenharth
2004-02-04  2:59       ` Walid Taha
2004-02-04  5:53         ` Andrew Lenharth
2004-02-05 21:29           ` Walid Taha
2003-10-27 19:17     ` Yann Regis-Gianas
2003-10-28 10:46       ` William Chesters
2004-02-04  2:22         ` Walid Taha
2004-02-04  2:56     ` Walid Taha
2003-10-28 15:09   ` Dmitry Lomov
2003-10-27 15:16 ` Vincent Balat [prof Moggi team]
2004-02-04  2:51 ` Walid Taha
2004-02-04 10:26   ` Ben Kavanagh
2004-02-04 10:32   ` Ben Kavanagh [this message]
2004-02-05 21:11     ` Walid Taha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000b01c3eb0a$356074e0$b1c92952@Archimedes' \
    --to=kavabean@lmi.net \
    --cc=caml-list@inria.fr \
    --cc=taha@cs.rice.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).