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

Allow to use delegate constructors as functions #760

Open
Happypig375 opened this issue Jun 23, 2019 · 4 comments

Comments

Projects
None yet
4 participants
@Happypig375
Copy link
Contributor

commented Jun 23, 2019

Allow to use delegate constructors as functions

Similar to the suggestion Allow to use struct constructors as functions, it would be nice if we use constructors of delegates as functions.

The existing way of approaching this problem in F# is creating wrapper functions.

let x = System.Converter<_, _> string // ok
let y = string |> System.Converter<_, _> // FS0805: Invalid use of a delegate constructor. Use the syntax 'new Type(args)' or just 'Type(args)'.
let z = string |> (fun x -> System.Converter<_, _> x) // ugly

This is especially useful for making Actions and Funcs explicitly.

Pros and Cons

The advantages of making this adjustment to F# are consistency, conciseness, blah, blah

The disadvantage of making this adjustment to F# is none that I can think of.

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S

Related suggestions:
Class constructors as functions - #158
Struct constructors as functions - #455

Both were completed for F# 4.0.

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

This comment has been minimized.

Copy link

commented Jun 24, 2019

These things are very rare and at the outer reaches of the type system, so while this feature would hurt no-one, it may cost more characters to implement than it would end up saving in avoiding fun x -> ... x.

@cartermp

This comment has been minimized.

Copy link
Member

commented Jun 26, 2019

I think this makes sense from a consistency perspective. I don't have a good sense for how often F# developers use delegates - no telemetry in either the compiler or standard library :)

@Happypig375

This comment has been minimized.

Copy link
Contributor Author

commented Jun 26, 2019

I hit this while trying to work around #248.

@7sharp9

This comment has been minimized.

Copy link
Member

commented Jun 26, 2019

In my experience they are only used when necessary, e.g. retro C# libs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.