Search code examples
haskellequalitygeneric-programming

Easiest way to compare values of big data type ignoring one field or without that field


I'm working with data type from library which has a lot of constructors and each constructor has several fields. Every constructor is defined using Record Syntax. And every constructor has field with the same name. I want to check equality of values of this data type but without this one field. I'm just not interested in it. What is the easiest and cleanest way to do? Perfectly, I would be extremely happy if something like this exist:

equalsWithout ignoredField value1 value2

The easiest way I can imagine is to translate this data type to [String] using Show and compare result lists. But I would like to avoid this because it require to write a lot of boilerplate code because data type has a lot of constructors... Maybe there's cleaner way to achieve this.


Solution

  • per your request:

    Copy the value from one to the other and then compare:

    a { foo = foo b } == b