Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Deokhwan Kim <dk@ropas.snu.ac.kr>
To: caml-list@yquem.inria.fr
Subject: The sharing mechanism in the  Marshal module
Date: Sat, 03 Mar 2007 23:59:25 +0900	[thread overview]
Message-ID: <45E98D4D.3020200@ropas.snu.ac.kr> (raw)

Hello,

I thought the following code would produce 2 in (* 1 *), but as it is it
outputs 1:

let incr =
let c = ref 0 in
function () -> c:= !c + 1 ; !c

let save =
Marshal.to_string incr [Marshal.Closures]

let incr1 =
(Marshal.from_string save 0 : unit -> int)

let () =
Printf.printf "%d\n" (incr ()) ;
Printf.printf "%d\n" (incr1 ()) (* 1 *)

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

Thanks.




             reply	other threads:[~2007-03-03 14:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-03 14:59 Deokhwan Kim [this message]
2007-03-04 14:38 ` Zheng Li
2007-03-07 14:59 ` [Caml-list] " Roland Zumkeller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45E98D4D.3020200@ropas.snu.ac.kr \
    --to=dk@ropas.snu.ac.kr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox