ppx_deriving icon indicating copy to clipboard operation
ppx_deriving copied to clipboard

`eq` does not derive `equal` for (anonymous) objects

Open zbaylin opened this issue 2 years ago • 0 comments

Example:

type t = < foo : int >
[@@deriving eq]

Expected behavior: An equality function for t is generated, i.e. something like:

let equal : t -> t -> bool = fun a b -> Int.equal a#foo b#foo

Actual behavior: The ppx gives the following error:

eq cannot be derived for < foo : int >

I use anonymous objects like these to simulate similar behavior with anonymous records in standard variants, i.e.

type variant =
  | Foo of {
    bar : int
  }

type poly = [ `Foo of < bar : int > ]

Is there a reason I can't think of that deriving equality functions for objects is non-trivial compared to records?

zbaylin avatar Nov 16 '23 14:11 zbaylin