Skip to content

eq does not derive equal for (anonymous) objects #271

@zbaylin

Description

@zbaylin

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions