-
Notifications
You must be signed in to change notification settings - Fork 22
Description
I propose we improve interop to C#-defined Nullable
-typed optional parameters
Consider a C# definition
public int SomeMethod(int? channels = 0, int? ratio = 1)
The compiled form of this uses Nullable
typed values for the parameters with default value nullref
.
We do not recognise this in F# and when calling and providing a value we require
C.SomeMethod(channels = Nullable 3)
C.SomeMethod(channels = Nullable 3, ratio = Nullable 3)
C.SomeMethod(ratio = Nullable 3)
Alternatives that achieve the same effect are
-
to allow auto-conversion from
T
toNullable<T>
at method calls. Indeed this is probably the best solution. -
some even more aggressive auto-conversion rule for
T
toNullable<T>
Pros and Cons
The advantages of making this adjustment to F# are interop with modern C# becomes smoother.
The disadvantages of making this adjustment to F# are
- another implicit conversion rule is added.
- we have to be careful this is not a breaking change
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
- This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
- I have searched both open and closed suggestions on this site 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.
Please tick all that apply:
- This is not a breaking change to the F# language design
- I or my company would be willing to help implement and/or test this