A pain point that I keep running into is naively passing a reason value in Js.log() and getting somewhat mangled output.
For any particular example, I’m able to convert it to something more js-friendly (for example, convert a list to an array, or convert a record to a Json.t or even a Js.Dict.t(string)), so I’m not looking for help on specific examples. I am, however, wondering if there are conventions or ways to make this easier.
In case it helps direct the discussion, here are two possible ways this could become easier:
-
Pure convention, but every time you define a new type, have the standard practice be to define a
let toJson : t => Json.t
function. Then, people would log viaJs.log(M.toJson(x))
. It would be especially important for library writers to expose this for all the types in their API. -
To make the above convention much easier, have the ability to derive a JSON representation of records/variants. For this, I’m thinking something like Jane Street’s
[@@deriving sexp]
that would recursively call toJson on record fields or variant payloads.
Thoughts?