-
Notifications
You must be signed in to change notification settings - Fork 782
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
"System.Func overload-is-better": checking if anything breaks, or not (in which case, we'd like a test) #11538
Changes from all commits
8343554
f2b6f3f
5d4a260
a657c2d
a292e4e
97389d3
c3bc6ed
31f8201
bf87fed
3a0a59e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
neg_at_somepoint_in_the_future_func-is-better-or-not.fsx(14,1,14,17): typecheck error FS0193: The method 'M' has overload with 'System.Func' delegate in the signature, to fix the warning, you need to specify the type explicitly. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrt to the warning message itself:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specifying the argument name may be problematic in circumstances similar to what @baronfel was dealing with, patterns and "anonymous" parameters. If there are places we already prettify Probably several error messages could benefit from having this kind of "expanding the expression to explain the error in actual case". |
||
|
||
neg_at_somepoint_in_the_future_func-is-better-or-not.fsx(16,1,16,19): typecheck error FS0193: The method 'M2' has overload with 'System.Func' delegate in the signature, to fix the warning, you need to specify the type explicitly. | ||
|
||
neg_at_somepoint_in_the_future_func-is-better-or-not.fsx(25,1,25,37): typecheck error FS0041: A unique overload for method 'M3' could not be determined based on type information prior to this program point. A type annotation may be needed. | ||
|
||
Known types of arguments: (unit -> unit) * (unit -> unit) | ||
|
||
Candidates: | ||
- member C.M3 : [<ParamArray>] funcs:Action array -> unit | ||
- member C.M3 : [<ParamArray>] funcs:Func<unit,unit> array -> unit | ||
|
||
neg_at_somepoint_in_the_future_func-is-better-or-not.fsx(38,5,38,63): typecheck error FS0193: The method 'Min' has overload with 'System.Func' delegate in the signature, to fix the warning, you need to specify the type explicitly. | ||
|
||
neg_at_somepoint_in_the_future_func-is-better-or-not.fsx(40,5,40,74): typecheck error FS0193: The method 'Min' has overload with 'System.Func' delegate in the signature, to fix the warning, you need to specify the type explicitly. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
open System | ||
|
||
type C() = | ||
member _.M(a: Action<int>) = printfn "M(action)" | ||
member _.M(f: Func<int, unit>) = printfn "M(func)" | ||
member _.M2(f: Func<unit, unit>) = printfn "M2(func())" | ||
member _.M2(f: Action) = printfn "M2(action())" | ||
member _.M3([<ParamArray>] funcs: Func<unit,unit> array) = printfn "M3(funcs)" | ||
member _.M3([<ParamArray>] funcs: Action array) = printfn "M3(actions)" | ||
let c = C() | ||
|
||
// https://github.com/dotnet/fsharp/issues/11534 | ||
// we may want a warning here, or maybe an error proper at some point | ||
c.M(fun _ -> ()) | ||
|
||
c.M2(fun () -> ()) | ||
|
||
c.M3(Action(fun () -> ()), (fun () -> ())) | ||
c.M3(Action id, id, id, id) | ||
c.M3(Func<_,_> id, id, id, id) | ||
c.M3(Func<_,_>(fun () -> ()), (fun () -> ())) | ||
c.M3((fun () -> ()), Func<_,_>(fun () -> ())) | ||
|
||
// this one doesn't resolve, although without the param array, it would | ||
c.M3((fun () -> ()), (fun () -> ())) | ||
|
||
|
||
open System.Collections.Generic | ||
open System.Linq | ||
|
||
// here we verify different style of calling BCL overloaded methods | ||
type Query = | ||
static member MinBy_ExplicitDelegate<'T, 'Q, 'Key when 'Key: equality and 'Key: comparison> (source: IEnumerable<'T>, valueSelector: 'T -> 'Key) = | ||
Enumerable.Min(source, Func<'T, 'Key>(valueSelector)) | ||
static member MinBy_ExplicitDelegateWithArgName<'T, 'Q, 'Key when 'Key: equality and 'Key: comparison> (source: IEnumerable<'T>, valueSelector: 'T -> 'Key) = | ||
Enumerable.Min(source, selector = Func<'T, 'Key>(valueSelector)) | ||
static member MinBy_Lambda<'T, 'Q, 'Key when 'Key: equality and 'Key: comparison> (source: IEnumerable<'T>, valueSelector: 'T -> 'Key) = | ||
Enumerable.Min(source, (fun (t: 'T) -> (valueSelector t))) | ||
static member MinBy_LambdaWithArgName<'T, 'Q, 'Key when 'Key: equality and 'Key: comparison> (source: IEnumerable<'T>, valueSelector: 'T -> 'Key) = | ||
Enumerable.Min(source, selector = (fun (t: 'T) -> (valueSelector t))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll be looking at reimplementing this in terms of
List.mapi2
, this has been first try to make things work (it passes the test, but the test likely doesn't covers all possible cases).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is problematic, I wrote it before surveying some more my assumptions (in #11544, which shows that my assumptions are just wrong).
Looking for guidance on how we want that to work to get this PR considered for merge.
Also eager to hear if there is a point or no, to move from
list list
representation ofSynValInfo
, I know @baronfel was facing slightly related question recently:which shows that the representation as we have it, from the parser AST down to the typed AST is a bit arcane to the people not used to it.