serialization

Stephen Weeks sweeks@wasabi.epr.com
Mon, 2 Aug 1999 15:20:15 -0700 (PDT)


> What happens currently if I serialize a ref?  Is the idea like Kali in that
> the receiver gets a copy of what the sender sends?  Is the `graph' structure
> of an object being sent preserved (or turned into a tree)?

Graph structure is preserved.  It's implemented like a gc with a single
root.

Here's the current regression test for serialization, along with the
output.

--------------------------------------------------------------------------------
open MLton

val l = [1, 2, 3, 4]

structure W = Word8
structure V = Word8Vector

val r = ref 0
val t = (r, r)

fun pv v = (V.app (fn w => (print(W.toString w); print " ")) v
	    ; print "\n")

fun pr s = (print s; print "\n")

fun pi i = (print(Int.toString i); print " ")
fun pl l = List.app pi l

fun 'a ds(a: 'a): 'a = deserialize(serialize a)
val pb = pr o Bool.toString
   
val _ =
   (pb(serialize l = serialize l)
    ; pl(ds l) ; print "\n"
    ; pb(l = ds l)
    ; pb(let val t: int ref * int ref = ds t
	 in #1 t = #2 t
	 end)
    ; pi(ds (fn x => x) 13)
    ; pi(ds (fn x => x + 1) 14)
    ; print "\n")
--------------------------------------------------------------------------------

true
1 2 3 4 
true
true
13 15 

--------------------------------------------------------------------------------