-
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
Improve interop to Nullable
optional parameters
#774
Comments
There is also this case when interoperating with C#-defined optionals, where the use of an F# Here the compiled form is:
and the C# form is public static Tensor add (Tensor x, Tensor y, string name = "Add")
{
var dict = new Dictionary<string, object>();
dict["x"] = x;
dict["y"] = y;
var op = _op_def_lib._apply_op_helper("Add", name: name, keywords: dict);
return op.output;
} |
@cartermp We have a compatibility problem with this Given this:
We currently require C.SomeMethod(ratio = Nullable 3) However the natural and "morally correct" thing is to require non-nullable, e.g. C.SomeMethod(ratio = 3) The problem is that, if the method is not overloaded, we use a "strong" assumption of Nullable, e.g. let f x = C.SomeMethod(ratio = x) will infer
Here's an example of a line that fails to compile with a type-adjusted "strong" rule. This also affects unnamed arguments, e.g. this line fails to compile I'm not really sure what to do about this. The current strong assumption of What do you think our position should be on this? The choices would be:
My gut feeling is that approach (2) would be adequate. |
My main concern here, though I think this is worth doing, is that usage of this kind of code is much more widespread than I thought (due to interfacing with DBs). It'd be good to get opinions from folks like @Thorium and others on this. |
Initially I have more questions than opinions: So you mean implicit conversion from So far the standard F#-type for maybe-monad has been In C#, null breaks SOLID principles by playing two roles:
Which one is this solution focusing to? Will this cause backward compatibility issues? Edit: |
No, this is not about a conversion but about proper treatment of nullable-typed optionals coming from C# code. |
Ok, I know mostly about SqlProvider, which is pure F#, not using C# Nullables, maybe other Sql tools are affected more. |
Nullable let me confusion: let x = Nullable(3)
let ty = x.GetType()
Assert.NotEqual(typeof<Nullable<int>>,ty)
Assert.Equal(typeof<int>,ty) example 2: Assert.Throws<System.NullReferenceException>(fun() ->
let ty = Nullable().GetType()
())
|> ignore those is auto drop the |
Closing out as completed for F# 5. |
@xp44mm, I know it’s been two years, but for posterity and others interested: this is just how |
I propose we improve interop to C#-defined
Nullable
-typed optional parametersConsider a C# definition
The compiled form of this uses
Nullable
typed values for the parameters with default valuenullref
.We do not recognise this in F# and when calling and providing a value we require
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
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:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: