Version française
Home     About     Download     Resources     Contact us    
Browse thread
let rec and environment sharing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel_Bünzli <daniel.buenzli@e...>
Subject: Re: [Caml-list] let rec and environment sharing

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