The pretty-printing facility is part of the toplevel library. You'll find the source in toplevel/genprintval.ml
. It's understandable, considering that it needs type information: you can't just throw any value at it, the choice of pretty-printer is based on the type.
If you want to use this code in your program, you'll need to link with the toplevel library (toplevellib.cma
) or compile in genprintval
(which means bringing in enough bits of the type checker to analyse the type, it can get pretty big).
There is a similar facility (but not sharing the code, I think) in the debugger (debugger/printval.ml
and debugger/loadprinter.ml
).
There are third-party libraries that you can directly link against and that provide pretty-printing facilities. Extlib's Std.dump
provides a very crude facility (not based on the type). Deriving by Jeremy Yallop and Jake Donham is another approach. This Caml Weekly News item offers more suggestions.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…