-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
equality combinators for variant types #197
Comments
i suspect this cannot be solved generally for unknown variant types. practically, what is the best way to provide an equality in the absence of polymorphic compare? write it all out with matching by hand? |
Yes, the clean way is to write it by hand (or use ppx_deriving.eq to do it for you). It's also fine to I don't think you can have a generic combinators. For non recursive types you might do this if most cases are trivial: type t = A of int * bool | B | C | …
let equal x y : bool = match x, y with
| A (i,_), A(j, _) -> CCInt.equal i j
| A _, _ | _, A _ -> false
| _ -> Pervasives.(=) x y edit: please re-open if the answer is not satisfying :) |
ok, thanks. good point to keep in mind that it's ok to use the polymorphic compare when the use case is unproblematic! |
Hi, open Containers
open Pervasives This stopped working since |
what's the best way to make equality functions for variant types? can there be a general combinator that says: all variants are unequal but within one variant, equality is decided by the argument of the constructor, with an inner equality function?
The text was updated successfully, but these errors were encountered: