[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Damien <Damien.Pous@e...> |
| Subject: | Re: [Caml-list] partial eval question |
On Mon, 27 Oct 2003 01:41:49 -0000 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? Multi-Stage Programming is your friend... <http://www.cs.rice.edu/~taha/MSP/> There are two ML implementations : Ocaml : MetaOCaml <http://www.cs.rice.edu/~taha/MetaOCaml/> SML : MetaML <http://www.cse.ogi.edu/PacSoft/projects/metaml/> 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>. Damien ------------------- 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