Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trying to solve #6477, but without implicit open
Rationale
As explained in #6477, we have the "infix explosion" problem. To relax it, I added some specialization to both type inference and primitive inspired by F#
https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/symbol-and-operator-reference/arithmetic-operators#operators-and-type-inference
The idea is, to extend the type inference rules for infix (and some unary) operations defined in Pervasives to specialize them for predefined types but fall back to
int
if they cannot be inferred or the types of the left-hand and right-hand are different.This doesn't make a breaking change, since the existing operations are defined on
int
already.However, we can introduce them as unified operators for the new codebase. They are still safe, as they are always specialized and not polymorphic.
Specialized operators:
\"~-"
%neg
int
,float
,bigint
\"~+"
%identity
int
,float
,bigint
\"+"
%add
int
,float
,bigint
,string
\"-"
%sub
int
,float
,bigint
\"*"
%mul
int
,float
,bigint
\"/"
%div
int
,float
,bigint
mod
%mod
int
,float
,bigint
\"**"
%pow
int
,float
,bigint
abs
%abs
int
,float
,bigint
land
%land
int
,bigint
lor
%lor
int
,bigint
lxor
%lxor
int
,bigint
lnot
%lnot
int
,bigint
lsl
%lsl
int
,bigint
lsr
%lsr
int
asr
%asr
int
,bigint
Side note
This PR doesn't attempt to add custom ops or polymorphic ops, but that's the specialized custom ops already possible by opening a module.
Polymorphic ops should deprecated. they are unpredictable and inefficient, as explained in #7031. So in future versions, comparison will have consistent behavior with this. It will be a breaking change, but we don't have a better alternative yet.