learn-ocaml
learn-ocaml copied to clipboard
Custom datatype printers?
Suppose I have a datatype for expressions such as
type exp =
| Num of int
| Plus of exp * exp
| Times of exp * exp
I would like to display these trees using an infix notation, so I can define a custom pretty-printer for them. Is there a way to register printers with learn-ocaml so that the datatype is printed according to the custom printer in the toplevel as well as when the automatic grader shows computing ... in the report?
Edit: upon further investigation, the pretty-printing routine in the test_lib.ml ultimately calls out to Toploop.print_value, which I believe will use printers registered through Toploop.install_printer. So if Toploop is exposed to test.ml, it should be possible to install custom printers.
In fact, in (eg) prepare.ml, you can do #install_printer your_printer;; : this will register your printer, which will be used in the test reports and in the toplevel.
When I try this, Cannot find type Topdirs.printer_type_new is printed in the toplevel and no printer is registered.
Hi
With learn-ocaml 0.12, I also experienced Cannot find type Topdirs.printer_type_new just as @wyschean. But with the recent learnocaml 0.13.0 (docker image) this seems to be fixed, and #install_printer in prepare.ml does work correctly for me (custom display of values both in the toplevel and in the grading report).