-
Notifications
You must be signed in to change notification settings - Fork 101
Improve internal type signature #623
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
base: master
Are you sure you want to change the base?
Conversation
Careless?
@@ -305,7 +305,7 @@ type GroupBy = | |||
static member GroupBy (x: list<'T>, f: 'T->'Key, _: list<'Key*list<'T>>, [<Optional>]_impl: GroupBy) = Seq.groupBy f x |> Seq.map (fun (x, y) -> x, Seq.toList y) |> Seq.toList | |||
static member GroupBy (x: 'T [] , f: 'T->'Key, _: ('Key*('T [])) [] , [<Optional>]_impl: GroupBy) = Seq.groupBy f x |> Seq.map (fun (x, y) -> x, Seq.toArray y) |> Seq.toArray | |||
|
|||
static member inline Invoke (projection: 'T->'Key) (source: '``C<'T>``) : '``C<'Key * 'C<'T>>`` = | |||
static member inline Invoke (projection: 'T->'Key) (source: '``Collection<'T>``) : '``Collection<'Key * 'Collection<'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.
Note the ticks in the type signature. The C here is more for documentation rather than an actual type
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.
Yes, it won't change any behavior. Not even a public signature.
But it reads better, so we can accept the PR as a code readability improvement.
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.
For sure, I’m wondering if @fxdmhtt has some issue with code? Something that does not compile?
@fxdmhtt please create an issue for this. with a small repro, then we can help and reference eventually a PR that will address it. We'll accept this PR but it's unlikely that it will solve any issue. |
I have seen your reply and I completely agree with what you said. I think it is more of my own problem and I didn't want to bother you about it. Please allow me to extract a minimal reproducible code tomorrow. Thank you very much! |
Thank you very much. The minimal example code is as follows: open FSharpPlus
let inline groupby (key: 'T -> 'Key when 'Key : equality) (sequence: '``Collection<'T>``) : Map<'Key, '``Collection<'T>``> =
sequence
|> groupBy key
|> Map.ofSeq I will get a wavy line error on groupBy:
This code doesn't really mean anything, I'm just more familiar with Python so I'm trying to simulate the behavior of the Toolz package. This is a toy. Specifically, I'm trying to wrap the generic groupBy as Toolz.groupby I'm a beginner in F# and don't know if this problem is caused by FSharpPlus, but as of now, I really don't have any idea to solve this compilation error. FSharpPlus: 1.7.0 Thanks again! Additional information: I found that when the function signature is changed to the following: let inline groupby (key: 'T -> 'Key when 'Key : equality) (sequence: '``Collection<'T>``) =
sequence
|> groupBy key
|> Map.ofSeq that is, the signature of the function output is removed. the compilation error will disappear, but the type inference will not be able to recognize the real information. The Ionide plugin infers:
I don't know how to modify |
The signature of GroupBy.Invoke function is abnormal, which causes the secondary encapsulated '
Collection<'T>
type to be incorrectly identified (identified as Id<'T>).Refer to ChunkBy.Invoke, this should be just a typo.