Skip to content
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

ping pong in documentation of == and === #38

Open
7sharp9 opened this issue Feb 13, 2018 · 2 comments
Open

ping pong in documentation of == and === #38

7sharp9 opened this issue Feb 13, 2018 · 2 comments

Comments

@7sharp9
Copy link
Contributor

7sharp9 commented Feb 13, 2018

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

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

@jack-pappas
Copy link
Owner

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 jack-pappas mentioned this issue Jul 15, 2018
6 tasks
@wallymathieu
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants