Atdgen - .atd for Constructors with more that one argument

Hey everyone,

Given that i want to generate this type,

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.

1 Like

@n4323 If i write my .atd file like 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">

I get this error though,

File "./bin/ml/person.atd", line 12, characters 31-32:
Expecting ']'

The error is pointing to first asterik *

hm, then i don’t know. it almost looks like atdgen chokes on constructors with more than one argument? i have no experience with it unfortunately.

Yes seems like that. Can’t find anything in their documentation as well

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.

1 Like