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
Long-term storage of values
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-02-29 (18:06)
From: Markus Mottl <markus.mottl@g...>
Subject: Re: [Caml-list] Long-term storage of values
On Fri, Feb 29, 2008 at 5:19 AM, Berke Durak <> wrote:
>  One major drawback of IO is that it does not handle sharing or recursive
>  structures.  And I know of no efficient, type-safe way of handling those,
>  especially if you don't want the serializer to add extra sharing (for instance
>  if you have distinct mutable records with the same contents)

It shouldn't be too hard to write a macro that generates code for
checking whether data marshalled out using the standard marshalling
function conforms to a type specification even in the presence of
shared or cyclic values.  You just need to store a type identifier in
an array for every structured value you encounter.  Whenever there is
a backreference in the marshalled data, you check whether the type
denoted by the identifier for the previously seen value unifies with
what you expect at the current position.  This should be sufficiently
efficient.  If this type checking succeeds, it should be safe to
unmarshal the data using the standard functions.


Markus Mottl