Alex Rivera | Logout

How can OCaml values be printed outside the toplevel?

Asked 2011-08-31T17:55:26.527
20

The OCaml repl ("toplevel") has rich printing for any types, user-defined or otherwise. Is it possible to access this functionality outside the toplevel, rather than having to write an entirely custom set of value printers for one's own entire set of types?

Edit
Report

1 Answer

10

The OCaml Batteries Included library contains the dump function in its BatPervasives module . It converts any value to a string and returns it. You can see its source code here. The output will not be identical to the toplevel, because some information is lost at runtime, e.g. abstract data type constructors will become integers.

answered 2011-08-31T21:57:53.133

Your Answer