Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
The sharing mechanism in the Marshal module
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-03-04 (14:38)
From: Zheng Li <li@p...>
Subject: Re: The sharing mechanism in the Marshal module


Deokhwan Kim <> writes:
> I thought the following code would produce 2 in (* 1 *), but as it is it
> outputs 1:
That's the semantic of marshal, it serialize functional values as *closures*,
i.e. functions carrying its whole environments.  In your example, the incr1
also gets a copy of incr's environment, which has a copy of c included.

Despite some flaws being spotted in the marshal module last month [1], as far
as your example goes, you should stick with the closure semantics.

> Why? In addtion, what should I do if I really want the sharing of the c
> counter between incr and incr1?

There are some workarounds, but it depends on why you need marshaling. In
many cases, you don't actually need marshal for a shallow copy.


Zheng Li