type constant =
Pconst_integer of string * char option
| Pconst_char of int
| Pconst_string of string * string option
| Pconst_float of string * char option
What should be in my .atd file? I tried this ,
type constant = [
Pconst_integer of (string * string option)
| Pconst_char of int
| Pconst_string of (string * string option)
| Pconst_float of (string * string option)
] <ocaml repr="classic">
But then i get this type,
type constant = Person_t.constant =
Pconst_integer of (string * string option)
| Pconst_char of int
| Pconst_string of (string * string option)
| Pconst_float of (string * string option)
which is not same as the one i want. It gives me an error when i try to interchangeably use them. Error message - This variant or record definition does not match that of type. They have different arities.
I believe this is the old issue with syntax for two-argument constructors
A of (int * int option) is a one-argument constructor where the argument is a pair of type int * int option, while A of int * int option is a two-argument constructor; the first argument is int, the second int option. It looks like your .atd file lists one-argument constructors where it should list two-argument constructors.
In the past when I heavily used Atd, I would use the custom wrapper for this. At least for me, my serialization target was JSON I would define my serialization structure in Atd any my types in OCaml when they didn’t match the obvious defaults.