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: 2003-10-27 (15:21) From: Vincent Balat [prof Moggi team] Subject: Re: [Caml-list] partial eval question
```
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 -> 'b -> 'b) -> 'b -> 'a -> int -> 'b = <fun>

# let power3 mul one x = power mul one x 3;;
val power3 : ('a -> 'b -> 'b) -> 'b -> 'a -> 'b = <fun>

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

```