You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using a C# library which has a set of overridden methods, they accept a lambda parameter.
The lambda parameter types are dependent on the generics defined in the class and method.
In f#, it cannot recognize the types of lambda params and requires specifying them...
However, it works perfectly in C#, without any additional movements.
Here is the source code.
It contains 2 methods.
The first one is demonstrating the issue,
the second one is the same, but with a workaround to make it compilable.
@vadim-kor I don't think this is a bug, it is just that you have the expectation that F# would resolve overload like C# does, but this is not the right assumptions.
It is painful to work it out, but overall, it makes me question the designs with zillions of overloads, especially when it is about Action, Func, in many of C# libraries design.
Also, since the methods seems to involve Func , this issue may be relevant:
There are things that can be improved in F# overload resolution though, but this is very sensible area and I think the community isn't too much focused in trying to make it work "just like C#" for those edge cases, because it comes with implications related to type inference, (something that C# doesn't do remotely to same extent that F# do) and risks of breaking changes (eagerly picking a wrong overload would be very very bad).
I think figuring out the few type annotations you need, and you gaining some insights about a right design to wrap the library in your F# code in the way that makes it easiest to maintain is your best approach for now.
If you are willing to see what it would take, in the type checker to make overload resolution better for this specific case, or just debugging through in order to surface more information about what makes F# skip the "right" overload, I'd be happy to give you cues into the compiler codebase, if you have ability to reach out on F# slack or discord.
Hello,
I'm using a C# library which has a set of overridden methods, they accept a lambda parameter.
The lambda parameter types are dependent on the generics defined in the class and method.
In f#, it cannot recognize the types of lambda params and requires specifying them...
However, it works perfectly in C#, without any additional movements.
Here is the source code.
It contains 2 methods.
The first one is demonstrating the issue,
the second one is the same, but with a workaround to make it compilable.
The used library is gremlinq: https://github.com/ExRam/ExRam.Gremlinq
It is working in c# absolutely fine.
Would be nice to have the same things working in F# as well.
I created a repo demonstrating the issue, with all required references:
https://github.com/vadim-kor/FSharp.GenericsRecognisionIssueDemo
The file demonstrating the issue:
https://github.com/vadim-kor/FSharp.GenericsRecognisionIssueDemo/blob/main/FSharp.IssueDemo/GremlinQueries.Issue.fs
Using .Net 7, latest version of F#.
The text was updated successfully, but these errors were encountered: