fsharp / fslang-suggestions

The place to make suggestions, discuss and vote on F# language and core library features
346 stars 21 forks source link

Recognize accessing members on delegate constructors as high-precedence applications #964

Open Happypig375 opened 3 years ago

Happypig375 commented 3 years ago
type private GetNameDelegate = delegate of Utf8JsonReader -> string
let tokenType = (GetNameDelegate(fun r -> nameof r.TokenType)).Invoke(Utf8JsonReader()) // OK
let tokenType2 = GetNameDelegate(fun r -> nameof r.TokenType).Invoke(Utf8JsonReader()) // FS0001 This expression was expected to have type 'GetNameDelegate' but here has type 'string'

https://github.com/fsharp/fslang-suggestions/issues/644 contains a section about High Precedence Application. It is weird for delegate constructors to be excluded from it.

Pros and Cons

The advantages of making this adjustment to F# are

  1. Consistency
  2. Convenience
  3. Conciseness

The disadvantages of making this adjustment to F# are (none)

Extra information

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

Related suggestions: #760 - Delegate constructors cannot be used as normal functions - i.e. cannot be piped into (Also opened by me lol)

Affidavit (please submit!)

Please tick this by placing a cross in the box:

Please tick all that apply:

For Readers

If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.

dsyme commented 3 years ago

I'll mark this as approved, it make sense to allow this (though I don't really see why you'd invoke a delegate right after constructing it?)