Version française
Home     About     Download     Resources     Contact us    
Browse thread
Metaprogramming features
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jonathandeanharrop@g...>
Subject: Re: [Caml-list] Re: Metaprogramming features
On Tuesday 07 October 2008 13:49:29 you wrote:
> Excerpts from jonathandeanharrop's message of Tue Oct 07 02:17:13 +0200 
2008:
> > Surely the discrepancy is because the translation should be:
> >
> >   let npower7 =
> >     let e = printf "power\n"; npower 7 (fun () -> x) in
> >     (fun () -> fun x -> e ()) ();;
>
> Hum "unbound value x" :)

Oh yeah. :-)

I hadn't noticed that you can do:

# .< fun x -> .~ .<x>. >.;;
- : ('a, 'b -> 'b) code = .<fun x_1 -> x_1>.

Which seems to be the source of my confusion. So "x" is bound inside the 
escaped code even though it was defined in the "fun x ->" of the bracketed 
code.

You are not allowed to do:

# .< fun x -> .~ x >.;;
Wrong level: variable bound at level 1 and used at level 0

That means a faithful translation into closures must capture such bound 
variables which will, in turn, defer the expression that does the 
constructing:

  let e x = printf "power\n"; npower 7 (fun () -> x)

and that now fails to incur side-effects at the same time as the MetaOCaml 
program.

So the translation from MetaOCaml to OCaml is not obvious at all.

This begs the question: could another formulation of MetaOCaml avoid these 
complications without losing expressiveness?

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e