caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* let rec and environment sharing
@ 2008-10-30 19:04 Daniel Bünzli
       [not found] ` <4d1b2df20810301240o77e110cft6070c5cd0ad863b6@mail.gmail.com>
  2008-10-31 21:17 ` Zheng Li
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Bünzli @ 2008-10-30 19:04 UTC (permalink / raw)
  To: OCaml Mailing List

Hello,

Is the closure's environment of definitions introduced by let rec  
shared between the definitions ?

Thanks for your answers,

Daniel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] let rec and environment sharing
       [not found] ` <4d1b2df20810301240o77e110cft6070c5cd0ad863b6@mail.gmail.com>
@ 2008-10-30 19:58   ` Daniel Bünzli
       [not found]     ` <4d1b2df20810310346j7824c379udceff0517c6eac94@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Bünzli @ 2008-10-30 19:58 UTC (permalink / raw)
  To: OCaml Mailing List


Le 30 oct. 08 à 20:40, Philippe Wang a écrit :

> If you mean
[...]

No I'm talking about the internal representation. For example if you  
implement objects with records :

> type o = { mutable m1 : unit -> bool; mutable m2 : unit -> int }
>
> let f bla =
>   let rec m1 () = bla = 0
>   and m2 () = bla + 1 in
>   { m1 = m1; m2 = m2 }

Then I hope that the closure's environment of m1 and m2 is shared,  
that they do not each store their own mapping from bla to value.

Another question I have is below, does bla leak after a call to m1 ?

> let g bla blu =
>  let rec o = { m1 = m1; m2 = m2 }
>  and m1 () =
>     let rec m1' () = blu = 0             (* new method definitions  
> refers only blu *)
>     and m2' () = blu + 1 in
>     o.m1 <- m1'; o.m2 <- m2';
>     bla = 0
>  and m2 () = bla + 1 in
>  o

Best,

Daniel


  
       

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] let rec and environment sharing
       [not found]         ` <4d1b2df20810310843k79ef135fn5deaa9632272dd97@mail.gmail.com>
@ 2008-10-31 16:10           ` Daniel Bünzli
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Bünzli @ 2008-10-31 16:10 UTC (permalink / raw)
  To: OCaml Mailing List


Le 31 oct. 08 à 16:43, Philippe Wang a écrit :

> I believe the answer is no.

Note that your example is not the same as mine, I do create a new  
closure (the inner m1') which doesn't refer to bla in the code and the  
pointer to the original m1 closure is overwritten.

And I'd prefer a non empirical answer...

Best,

Daniel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: let rec and environment sharing
  2008-10-30 19:04 let rec and environment sharing Daniel Bünzli
       [not found] ` <4d1b2df20810301240o77e110cft6070c5cd0ad863b6@mail.gmail.com>
@ 2008-10-31 21:17 ` Zheng Li
  2008-11-01 10:40   ` Daniel Bünzli
  1 sibling, 1 reply; 5+ messages in thread
From: Zheng Li @ 2008-10-31 21:17 UTC (permalink / raw)
  To: Daniel Bünzli; +Cc: OCaml Mailing List

Hi

Daniel Bünzli wrote:
> Hello,
> 
> Is the closure's environment of definitions introduced by let rec shared 
> between the definitions ?

AFAIK, the answer is yes.

  - I once saw this on a teaching slide of Xavier Leroy (I don't 
remember which one, but you can probably find it on his webpage)

  - I did encounter this encoding when implementing Vprint

Btw, it is called infix pointers, and there's a "infix" tag for OCaml 
block value.

HTH.

--
Zheng


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: let rec and environment sharing
  2008-10-31 21:17 ` Zheng Li
@ 2008-11-01 10:40   ` Daniel Bünzli
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Bünzli @ 2008-11-01 10:40 UTC (permalink / raw)
  To: OCaml Mailing List


Le 31 oct. 08 à 22:17, Zheng Li a écrit :

> AFAIK, the answer is yes.
>
> - I once saw this on a teaching slide of Xavier Leroy (I don't  
> remember which one, but you can probably find it on his webpage)

Maybe your thinking about this [1]. It states that ocaml uses minimal  
environments hence my second example shouldn't leak.

> Btw, it is called infix pointers, and there's a "infix" tag for  
> OCaml block value.


If this corresponds to what is described in the same document. Then  
the mutually recursive definitions should share the same environment.

Thanks,

Daniel

[1] http://pauillac.inria.fr/~xleroy/dea/compil/fermetures


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-01 10:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-30 19:04 let rec and environment sharing Daniel Bünzli
     [not found] ` <4d1b2df20810301240o77e110cft6070c5cd0ad863b6@mail.gmail.com>
2008-10-30 19:58   ` [Caml-list] " Daniel Bünzli
     [not found]     ` <4d1b2df20810310346j7824c379udceff0517c6eac94@mail.gmail.com>
     [not found]       ` <265BA436-5079-47E2-862E-9A1CD15ECDCB@erratique.ch>
     [not found]         ` <4d1b2df20810310843k79ef135fn5deaa9632272dd97@mail.gmail.com>
2008-10-31 16:10           ` Daniel Bünzli
2008-10-31 21:17 ` Zheng Li
2008-11-01 10:40   ` Daniel Bünzli

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