Currently I'm trying to use Batteries with ppx_deriving.show or something similar.
I am wondering how to use them together usefully.
To create dumping functions, I feel ppx_deriving.show is useful. But I have a little bit troubles using them together like the followings.
open Batteries
type t = { a: (int,int) Map.t }
[@@deriving show]
Now Map.pp is not defined, so it can't be compiled.
My adhoc fix is that I create module Map which include Batteries.Map and define function pp.
open Batteries
module Map = struct
include Map
let pp f g fmt t = ... (* create dump function by man hand *)
end
type t = { a: (int,int) Map.t }
[@@deriving show]
It works, but it is painful for me to adapt all of data structures...
Core with ppx_deriving.sexp is an alternative choice, but I prefer Batteries with ppx_deriving.show.
Does anybody know how to solve the problem?
Your fix is the right way. If you want to use deriving for data types
M.tdeclared without[@@deriving], you have to give its methods such asM.ppforshowby yourself:There is a way to partially automate this:
It generates
M.ppfor typetusingderiving.With
ppx_import, you can avoid copy-and-pasting of the definition:This should be expanded to the former code.
As you have found out, deriving
showofMap.tis not really useful though: normally you do not want to see the binary tree representation ofMap.tunless you are debuggingMapmodule itself.