-
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 |
This looks like a bug/limitation. I mean, your repro code goes a bit far into the limits of this library / F# type inference limitations. Having said that, at first sight it looks easy to solve. I can give it a try. |
There are many Have you considered replacing all |
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.
See in Distinct
, DistinctBy
, Rev
, and all Sort
related Invokables have also the abbreviated C<
T>` type signature.
Please apply the same change to them, so we can merge this.
See my review, or just do a find
I rarely do these kind of PRs that only impact code readability, I'm not saying it's bad, it's just that since I have limited time I prefer to focus myself in solving functionality issues. So, it's good to have collaborators who take care of code uniformity. It definitely helps in the long run. |
…ve clarity and consistency in type references for collection operations. Enhances readability and aligns with naming conventions.
Please review the patch |
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.
OK from my side, let's see if CI agree as well ;)
Sorry. I saw the CI error, but I don't have the ability to fix it. In fact, I raised this issue because I encountered difficulties in using F# type inference. I need your help. Thank you very much. |
No worries. I will fix it and merge it. |
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.