For simple types, [@@deriving eq] falls back on =:
|
| true, ([%type: int] | [%type: int32] | [%type: Int32.t] | |
|
[%type: int64] | [%type: Int64.t] | [%type: nativeint] | |
|
[%type: Nativeint.t] | [%type: float] | [%type: bool] | |
|
[%type: char] | [%type: string] | [%type: bytes]) -> |
|
[%expr (fun (a:[%t typ]) b -> a = b)] |
It sounds reasonable, and in general is fine. In the very specific case of nan, though, it will reach the typical thing that nan <> nan. In the standard library, however, there is Float.equal that does equate nan with itself. I think we should use that one, because:
[@@deriving eq] behaves differently on type t = float and on type t = Float.t.
- As long as a float appears in a structure, it does not hold that, with
[@@deriving eq, ord], equal x y = (compare x y = 0).
eq argues that monomorphic equality is better (which, hell yeah), so one might expect Float.equal rather than a fallback on =. (This one is pretty subjective, I suppose.)
The big downside, today, would be that this introduces a breaking change; bummer.
For simple types,
[@@deriving eq]falls back on=:ppx_deriving/src_plugins/eq/ppx_deriving_eq.ml
Lines 70 to 74 in e58e37d
It sounds reasonable, and in general is fine. In the very specific case of
nan, though, it will reach the typical thing thatnan <> nan. In the standard library, however, there isFloat.equalthat does equatenanwith itself. I think we should use that one, because:[@@deriving eq]behaves differently ontype t = floatand ontype t = Float.t.[@@deriving eq, ord],equal x y = (compare x y = 0).eqargues that monomorphic equality is better (which, hell yeah), so one might expectFloat.equalrather than a fallback on=. (This one is pretty subjective, I suppose.)The big downside, today, would be that this introduces a breaking change; bummer.