Skip to content

Custom datatype printers? #184

@tsani

Description

@tsani

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions