We’re happy to announce a new alpha release of Introcaml, an extension of OCaml that brings polymorphic printing. It allows printing and inspecting values of any type, without writing printer functions. See the first announcement for an introduction.
Introcaml is developed at Shogan.ai.
This release ports Introcaml to OCaml 5.5.2. To try it:
opam switch create 5.5.2+introcaml
What’s new
JSON printer
A generic JSON printer is available in Introspect.Json.*, intended for debugging (and piping through jq
):
# Introspect.Json.to_channel stdout [
`Point {x = 5; y = 0};
`String "foo";
`List [Result.Ok true; Result.Error false]
];;
[{"Point":{"x":5,"y":0}},{"String":"foo"},{"List":[{"Ok":true},{"Error":false}]}]
- : unit = ()
#
Debugging flags
-dblock-descshows descriptors in-dlambdaand similar output.-verbosereports descriptor collisions at link time.
Compatibility
Object files and executables (exec, cmo, cma, cmx, cmxa, cmxs) now use Introcaml-specific magic numbers (Caml1999?901). cmi, cmt and ast files keep the upstream format.
js_of_ocaml support
Although this was done in the js_of_ocaml repository, I think it is relevant to point the work we did @hhugo to bring full compatibility with Introcaml. js_of_ocaml can now be installed in Introcaml switches and javascript builds can now be instrumented. This brings polymorphic printing to OCaml programs compiled with js_of_ocaml, at no observable runtime cost (in our experiments).
There is also opt-in integration with the browser’s JavaScript console (console.log) and debugger, though this appears to be Chrome-only as far as I can tell. See how to enable it.
Bug fixes
- Descriptor collisions: descriptors are hashed better, reducing collisions. When they still collide, values are printed raw instead of with the wrong names.
- Descriptor representation: the representation is simpler and more portable.
- Missing descriptors: I fixed a few cases where descriptors were omitted or lost during compilation (large native allocations,
#loadin the toplevel). - Float arrays and records: this fixes bugs reported by @vouillon (#5, #6, #7), paving the way toward compatibility with wasm_of_ocaml.
- Printing:
~stepsnow bounds long lists and arrays, and printing is domain-safe.
Introcaml also received the “Claude treatment” to catch bugs I missed
.