Skip to content

deriving different equality functions for the same type #249

@mjambon

Description

@mjambon

We have a large AST definition made of many node types and we'd like to derive two different sets of equality functions:

  • one using structural equality, ignoring node IDs
  • one using only the node IDs

Our code looks like this:

type stmt = {
  id : int [@deriving equal fun _ _ -> true]; (* ignore if generated function prefix is "equal_" *)
  value : stmt_value [@deriving equal2 fun _ _ -> true]; (* ignore if prefix is "equal2_" *)
}
and stmt_value = ...
and expr = ...
...
[@@deriving eq, eq2] (* "eq2" is hypothetical, generates functions with prefix "equal2_" *)

We want one set of functions with the equal_ prefix and another set with the equal2_ prefix (or better, a custom name).

Is there currently a way to do such thing? Any suggestion on how to make this work?

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