Version française
Home     About     Download     Resources     Contact us    
Browse thread
Marshal.to_string and closures
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Julien SIGNOLES <julien.signoles@c...>
Subject: Marshal.to_string and closures
Hello,

I have a not-so-easy-to-reproduce case in which
=====
let tbl = Hashtbl.create 7
let f x = Hashtbl.find tbl x
let g b = Marshal.to_string (fun _ -> f b) [ Marshal.Closures ]
...
let _ = g ...
=====
may raise the exception
=====
Fatal error: exception Invalid_argument("output_value: abstract value
(Abstract)").
=====

If I wrote the above code like below, all is fine:
=====
let tbl = Hashtbl.create 7
let f x = Hashtbl.find tbl x;;
let g b = 
  let y = f b in
  Marshal.to_string (fun _ -> y) [ Marshal.Closures ]
...
let _ = g ...
=====

After debugging, that is the marshalling of the field 1 of the closure
(the environment?) which raises this exception.

Can someone confirm that such a behaviour is possible whenever the
environment contains a value tagged as abstract? Or in any other cases?

If that is a known behaviour for Marshal.to_string, maybe it could be
properly documented?

Best regards,
Julien Signoles