-
Notifications
You must be signed in to change notification settings - Fork 21
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
Open up isNotNull, adding it to the top-level functions for the rest of us #883
Comments
The latest decision is to remove it from FSharp.Core as it has the form So anything null-related should now be considered in the light of https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1060-nullable-reference-types.md, as anything that can be exposed as null should be an NRT . Perhaps
The RFC says |
@charlesroddie The operators can be overloaded, custom equality can have been defined. This is true for any CLR language, and therefore, the general rule of thumb is not to use that. C# added And if you would argue that it shouldn't matter if it's overloaded or not, using C# 8 introduced
The function |
isNotNull would be extremely useful, since it's used in code much more often than isNull |
All the linked issues are covered by https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1060-nullable-reference-types.md . Should this issue be closed as a result @abelbraaksma ? In particular when this is implemented, things that can be null in .Net can be deconstructed using the syntax: let len (str: string?) =
match str with
| null -> -1
| NonNull s -> s.Length If there is anything missing in the RFC, best to add to the discussion thread linked to there. |
@charlesroddie I don't think the RFC you mentioned is relevant, the pattern that is used very often when integrating with nullable objects is the following if isNotNull someObject then
doWork() What you are suggesting is reversing the flow, which is less readable match someObject with
| null -> ()
| NonNull _ -> doWork() |
@charlesroddie, it's probably going to be closed because there's pushback, though the referred issue, introducing |
I agree with @charlesroddie that this would only be actioned in the context of https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1060-nullable-reference-types.md |
Fair enough. We should take it up there. |
This is not |
Allow usage of
isNotNull
as counterpart forisNull
The function
isNotNull
already exists. I propose to removeinternal
so that we can use it and that we help people write better code when struggling withnull
andisNull
.Pros and Cons
The advantages of making this adjustment to F# are:
isNull
and the counterpartx <> null
, we should strive to ban that, andisNotNull
can helpisNull
when it seesx == null
orx <> null
, which leads to debate in the latter case: Lint suggests "not (isNull x)" over "x <> null" fsprojects/FSharpLint#439x <> null
thannot(isNull x)
. HavingisNotNull
will help guide in the right direction (see this lengthy Slack chat where I unsuccessfully try to explain why usingx <> null
is badnot(isNull x)
, if less code is emitted, a larger chance exists that the optimizer catches more cases, and method bodies can remain under the JIT threshold for inliningThe disadvantages of making this adjustment to F# are
Extra information
Estimated cost (XS, S, M, L, XL, XXL): XXXXS
Related suggestions: #99
Affidavit (please submit!)
Please tick this by placing a cross in the box:
isNotNull
, or name itisNonNull
, if that reads better. Both are present currently in the source.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.Please tick all that apply:
The text was updated successfully, but these errors were encountered: