List Info

Thread: "ocaml_beginners"::[] Can't Marshal objects?




"ocaml_beginners"::[] Can't Marshal objects?
country flaguser name
United States
2007-03-10 21:57:10

I have the following code (HashSet is from http://wwwteor.mi.infn.it/
~pernici/ocaml/ocaml.html):

class obj2 =
object (self)
val mutable parents = HashSet.create 100 ""
val mutable props = (Hashtbl.create 100 : (string, string)
Hashtbl.t)
method get_prop p = Hashtbl.find props p
(* method set_prop p v = Hashtbl.find props p *)
method add_par par = HashSet.add parents par
method get_pars = HashSet.keys parents
end;;

For the following line:

... let o = new obj in let oser = to_string o [] in ...

I get the following runtime error:

Fatal error: exception Invalid_argument("output_value: functional
value")

I can serialize things like Hashtbl's and HashSet's just fine though.
Is OCaml trying to serialize my methods somehow? (I thought this was
possible anyway.) How do I fix this? (I just want it to pickle my
data and not the code, a la Python's pickle.) Thanks in advance.

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Re: Can't Marshal objects?
country flaguser name
Moldova, Republic of
2007-03-12 02:13:06

Shalom, Zheng.

ZL> Instead, I got a question for the list: since the
ZL> runtime can judge whether a value contains functional
ZL> value and should be marshaled with closure, why does it
ZL>; require the programmers to write that ?

"Semantic" reason: sometimes programmer wants to read
marshalled datastructures using another program, and when
programmer doesn't specify flag "Closures", he is sure that
function values won't be serialized and mashalled data will
be read successfully.
(of course, when marshalling algorithm remains fixed)

Sometimes I used marshalling to check whether my
data structure contains functional values or not, and
sometimes I prevented marshalling of some data structures
by including any functional value in it. So, "Closures"
flag is very useful for me.

"Effectiveness" reason #1: marshalling functional value
requires computation of MD5 hash of program, which requires
some time (computation is performed once per program run,
so it is not very time-consuming).

"Effectiveness" reason #2: each functional value uses
additional 16 bytes of serialized data to store MD5 of
program.

--
WBR,
dmitry mailto: gds-mlsts%40moldavcable.com">gds-mlstsmoldavcable.com

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )