Open kevmal opened 1 year ago
For reference, page 38 of https://fsharp.org/specs/language-spec/4.1/FSharpSpec-4.1-latest.pdf:
In the preceding table, leading
.
characters are ignored when determining precedence for infix operators. For example,.*
has the same precedence as*
. This rule ensures that operators such as.*
, which is frequently used for pointwise-operation on matrices, have the expected precedence.
We should clarify the specification instead to match the implementation, given the backwards compat constraints involved.
@dsyme This was per-approved here: https://github.com/dotnet/fsharp/issues/13051 have things changed?
It's a bit awkward since, for example, a neural network lib may want an "and" operator that results in a non-bool type, but the order of operations ends up being off making readability difficult.
Thanks @kevmal , yes I've reopened.
My bar on breaking changes shifts around a bit - this is right on the margin.
@vzarytovskii Could you bar-check you think this is a reasonable thing to change if placed under a langversion switch? It does make the language more consistent in the area of operators, which have too many corner-cases like this.
I propose we adjust the precedence for infix operators with a leading dot, such as
(.&&)
,(.||)
,(..&&)
, etc. , to make them equivalent to their counterparts without the leading dot, such as(&&)
, as specified in the F# language specification.The existing way of approaching this problem in F# is to use additional brackets to achieve the correct order of operations, but this does not match the language specification and causes confusion and unexpected behavior.
Pros and Cons
The advantages of making this adjustment to F# are:
a = b .&& b > c
not matchinga = b && b > c
.The disadvantages of making this adjustment to F# are:
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: None
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply: