Skip to content
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

Issues with type recognition #15572

Closed
vadim-kor opened this issue Jul 7, 2023 · 2 comments
Closed

Issues with type recognition #15572

vadim-kor opened this issue Jul 7, 2023 · 2 comments

Comments

@vadim-kor
Copy link

vadim-kor commented Jul 7, 2023

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.

image

image

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#.

@smoothdeveloper
Copy link
Contributor

@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.

You may see this comment:

#2503 (comment)

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:

#11534

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.

@0101
Copy link
Contributor

0101 commented Jul 10, 2023

@0101 0101 closed this as completed Jul 10, 2023
@github-project-automation github-project-automation bot moved this from Not Planned to Done in F# Compiler and Tooling Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants