fsharp / fsharp/fslang-suggestions
[Breaking] Avoid boxing on equality and comparison
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
**I propose we** solve https://github.com/dotnet/fsharp/issues/526 (accepting the breaking change at https://github.com/dotnet/fsharp/pull/9404 due to use of `IEquatable` and `IComparable`). We will include a `BackCompat` module to enable past behaviour. These current behaviours typically have no known instance of usage and the breaking change is only theoretical for code that already is designed poorly in the first place, like `.Equals` behaving differently from `IEquatable` and relying on `nan <> nan` without using `System.Double.IsNaN` (`IEquatable` makes `nan = nan`).
**The existing way of approaching this problem in F# is** taking the cost of boxing every equality and comparison for structs. Retaining the same behaviour has made F# perform worse than C#. We are keeping a reason for C# people not to move over simply because we retain a behaviour no one wants.
https://github.com/dotnet/fsharp/issues/526#issuecomment-1045552667
> Anyway, it has lost me as an fsharp developer, which is a shame as I really love writing code in fsharp, but with advancements in csharp over the years, it's, for the type of code I write, a lesser worse option
## Pros and Cons
**The advantages of making this adjustment to F# are**
1. Great performance
2. One less reason for C# people not to move over
3. One less reason for people to abandon F#
**The disadvantage of making this adjustment to F# is** this is a breaking change after all. But as mentioned, it's a hypothetical breaking change only. There is no known instance of people depending on `IEquatable` behaving differently from `.Equals` as this is poor design.
## Extra information
**Estimated cost (XS, S, M, L, XL, XXL):** S
**Related suggestions:**
We should do this together with another wart in FSharp.Core that has gone unnoticed, in the same update: https://github.com/fsharp/fslang-suggestions/issues/472
## Affidavit (please submit!)
Please tick this by placing a cross in the box:
* [x] This is not a question (e.g. like one you might ask on [stackoverflow](http://stackoverflow.com)) and I have searched stackoverflow for discussions of this issue
* [x] I have [searched both open and closed suggestions on this site](http://github.com/fsharp/fslang-suggestions/issues) and believe this is not a duplicate
* [ ] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
This is arguing against a previous decision not to accept this breaking change.
Please tick all that apply:
* [ ] This is not a breaking change to the F# language design
* [x] I or my company would be willing to help implement and/or test this
## For Readers
If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue names no implementation files or tests. Start with the linked issue #526 and pull request #9404, then review the discussion and related suggestion #472; done means an agreed breaking-change design is implemented and the BackCompat module preserves prior behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- compilers, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100