ExtCore icon indicating copy to clipboard operation
ExtCore copied to clipboard

ping pong in documentation of == and ===

Open 7sharp9 opened this issue 7 years ago • 2 comments

== refers to obsolete use === === refers to obsolete use ==

https://github.com/jack-pappas/ExtCore/blob/master/ExtCore/Pervasive.fs#L105-L113

7sharp9 avatar Feb 13 '18 22:02 7sharp9

Thank you for bringing this up. You're right, it should be fixed.

Background context: I think I originally used === for the physical equality (aka reference equality) operator, but later introduced == because that's what OCaml's Pervasives module uses and I thought it might be more familiar for anyone switching between F# and OCaml.

However, I failed to consider whether == would be confusing for C# developers getting into F#. After speaking to a developer at work who ran into that exact issue (== vs. =), I realized the C# -> F# scenario is much more likely and having an auto-imported == operator means that:

  • Devs used to working in C# can use == and won't get a syntax error telling them they should be using = instead.
  • If comparing two reference-typed things (e.g. F# records or DUs), accidentally using == instead of = means the program will compile but will almost certainly not have the expected behavior.

I think the solution here is to make a breaking change in ExtCore 1.0 to remove the == operator and un-deprecate ===. It'll eliminate confusion for developers new to F# and it'll fix this circular-deprecation issue as well. If we need to preserve the == operator, I think it's probably best to move it over to the FSharp.Compatibility.OCaml project under fsprojects/FSharp.Compatibility.

jack-pappas avatar Jul 15 '18 16:07 jack-pappas

From what I can see it's already implemented in ocaml compatibility https://github.com/fsprojects/FSharp.Compatibility/blob/master/FSharp.Compatibility.OCaml/Pervasives.fs#L53-L59

/// e1 == e2 tests for physical equality of e1 and e2.

let inline ( == ) x y =

    LanguagePrimitives.PhysicalEquality x y



/// Negation of (==).

let inline ( != ) x y =

    not <| LanguagePrimitives.PhysicalEquality x y

wallymathieu avatar Jul 17 '18 11:07 wallymathieu