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

FSharpFunc => Action/Func implicit conversion #2907

Closed
vasily-kirichenko opened this issue Apr 24, 2017 · 9 comments
Closed

FSharpFunc => Action/Func implicit conversion #2907

vasily-kirichenko opened this issue Apr 24, 2017 · 9 comments

Comments

@vasily-kirichenko
Copy link
Contributor

vasily-kirichenko commented Apr 24, 2017

It's super annoying that F# functions are not converted automatically to Action/Func when passed to methods:

image

So we have to write ugly code like this Action<_> (printfn "%s") or like this fun x -> printfn "%s" x

@matthid
Copy link
Contributor

matthid commented Apr 24, 2017

This adds some corner cases and implicit typing to the language. Maybe another way would be to have an operator for this, which converts to Action/Func as needed? And a special error message could show or advice that operator?

@vasily-kirichenko
Copy link
Contributor Author

@matthid the compiler already converts lambdas to Action/Func and it's caused no problems so far, so why not to do the same for any value of type FSharpFunc?

@matthid
Copy link
Contributor

matthid commented Apr 24, 2017

@vasily-kirichenko But from a users perspective that's not an implicit conversion, instead the user is writing an action or func in that case (I guess that's a philosophical question). Maybe @dsyme can share his opinion on this.

@isaacabraham
Copy link
Contributor

@matthid I had the same idea re: improve error reporting with guidance on how to convert (perhaps not even operators, just a few utility funcs added to FSharp.Core?)

@smoothdeveloper
Copy link
Contributor

@vasily-kirichenko consider adding some elements to #2503

@smoothdeveloper
Copy link
Contributor

IMHO this is a problem with delegates altogether, not only Action Func.

@matthid
Copy link
Contributor

matthid commented Apr 24, 2017

Thanks @smoothdeveloper after fsharp/fslang-suggestions#248 (comment) I kind of changed my mind. Maybe we need it to just work :)

@dsyme
Copy link
Contributor

dsyme commented Apr 24, 2017

@matthid @vasily-kirichenko @smoothdeveloper Yes, this is a glitch (my fault, sorry...) that should be fixed. I've marked fsharp/fslang-suggestions#248 as approved in principle

Next steps would be to dig into the "single overload" path of method overload resolution and understand why it differs from the "multiple overload" path. (F# applies specific rules to single overload method groups to process curried members - which can't be overloaded - among other things)

@dsyme
Copy link
Contributor

dsyme commented May 9, 2017

Closing as this is an approved RFC, we just need to implement this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants