Skip to content

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

Merged
merged 4 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions src/FSharpPlus/Control/Collection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ type Distinct =
static member Distinct (x: list<'a>, [<Optional>]_impl: Distinct) = List.distinct x
static member Distinct (x: 'a [] , [<Optional>]_impl: Distinct) = Array.distinct x

static member inline Invoke (source: '``C<'T>``) : '``C<'T>`` =
static member inline Invoke (source: '``Collection<'T>``) : '``Collection<'T>`` =
let inline call_2 (a: ^a, b: ^b) = ((^a or ^b) : (static member Distinct : _*_ -> _) b, a)
let inline call (a: 'a, b: 'b) = call_2 (a, b)
call (Unchecked.defaultof<Distinct>, source)
static member inline InvokeOnInstance (source: '``C<'T>``) : '``C<'T>`` = (^``C<'T>`` : (static member Distinct : _->_) source) : ^``C<'T>``
static member inline InvokeOnInstance (source: '``Collection<'T>``) : '``Collection<'T>`` = (^``Collection<'T>`` : (static member Distinct : _->_) source) : ^``Collection<'T>``

static member inline Distinct (x: '``Collection<'T>`` , [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.distinct |> OfSeq.Invoke : '``Collection<'T>``
static member inline Distinct (x: '``collection<'T>`` , [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.distinct |> OfSeq.Invoke : '``collection<'T>``

static member inline Distinct (x: ^``Collection<'T>`` , [<Optional>]_impl: Default1) = (^``Collection<'T>`` : (static member Distinct : _->_) x) : '``Collection<'T>``
static member inline Distinct (x: ^``collection<'T>`` , [<Optional>]_impl: Default1) = (^``collection<'T>`` : (static member Distinct : _->_) x) : '``collection<'T>``
static member inline Distinct (_: ^t when ^t : null and ^t : struct, _mthd: Default1) = id


Expand All @@ -288,14 +288,14 @@ type DistinctBy =
static member DistinctBy (x: list<'a> , f, [<Optional>]_impl: DistinctBy) = List.distinctBy f x
static member DistinctBy (x: 'a [] , f, [<Optional>]_impl: DistinctBy) = Array.distinctBy f x

static member inline Invoke (projection: 'T->'Key) (source: '``C<'T>``) : '``C<'T>`` =
static member inline Invoke (projection: 'T->'Key) (source: '``Collection<'T>``) : '``Collection<'T>`` =
let inline call_2 (a: ^a, b: ^b, f) = ((^a or ^b) : (static member DistinctBy : _*_*_ -> _) b, f, a)
let inline call (a: 'a, b: 'b, f) = call_2 (a, b, f)
call (Unchecked.defaultof<DistinctBy>, source, projection)
static member inline InvokeOnInstance (projection: 'T->'Key) (source: '``C<'T>``) : '``C<'T>`` = (^``C<'T>`` : (static member DistinctBy : _*_->_) source, projection) : ^``C<'T>``
static member inline InvokeOnInstance (projection: 'T->'Key) (source: '``Collection<'T>``) : '``Collection<'T>`` = (^``Collection<'T>`` : (static member DistinctBy : _*_->_) source, projection) : ^``Collection<'T>``

static member inline DistinctBy (x: '``Collection<'T>``, f , [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.distinctBy f |> OfSeq.Invoke : '``Collection<'T>``
static member inline DistinctBy (x: ^``Collection<'T>``, f , [<Optional>]_impl: Default1) = (^``Collection<'T>`` : (static member DistinctBy : _*_->_) f, x) : '``Collection<'T>``
static member inline DistinctBy (x: '``collection<'T>``, f , [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.distinctBy f |> OfSeq.Invoke : '``collection<'T>``
static member inline DistinctBy (x: ^``collection<'T>``, f , [<Optional>]_impl: Default1) = (^``collection<'T>`` : (static member DistinctBy : _*_->_) f, x) : '``collection<'T>``
static member inline DistinctBy (_: ^t when ^t : null and ^t : struct, _ : 'T -> 'U, _mthd: Default1) = id


Expand All @@ -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>>`` =
Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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?

let inline call_3 (a: ^a, b: ^b, c: ^c, p) = ((^a or ^b or ^c) : (static member GroupBy : _*_*_*_ -> _) b, p, c, a)
let inline call (a: 'a, b: 'b, p) = call_3 (a, b, Unchecked.defaultof<'r>, p) : 'r
call (Unchecked.defaultof<GroupBy>, source, projection)
Expand Down Expand Up @@ -348,15 +348,15 @@ type Rev =
static member Rev (x: list<'a> , [<Optional>]_impl: Rev ) = List.rev x
static member Rev (x: 'a [] , [<Optional>]_impl: Rev ) = Array.rev x

static member inline Invoke (source: '``C<'T>``) : '``C<'T>`` =
static member inline Invoke (source: 'Collection) : 'Collection =
let inline call_2 (a: ^a, b: ^b) = ((^a or ^b) : (static member Rev : _*_ -> _) b, a)
let inline call (a: 'a, b: 'b) = call_2 (a, b)
call (Unchecked.defaultof<Rev>, source)
static member inline InvokeOnInstance (source: '``C<'T>``) : '``C<'T>`` = (^``C<'T>`` : (static member Rev : _->_) source) : ^``C<'T>``
static member inline InvokeOnInstance (source: 'Collection) : 'Collection = (^Collection : (static member Rev : _->_) source) : ^Collection

static member inline Rev (x: '``Collection<'T>``, [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.rev |> OfSeq.Invoke : '``Collection<'T>``
static member inline Rev (x: 'collection, [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.rev |> OfSeq.Invoke : 'collection

static member inline Rev (x: ^``Collection<'T>``, [<Optional>]_impl: Default1) = (^``Collection<'T>`` : (static member Rev : _->_) x) : '``Collection<'T>``
static member inline Rev (x: ^collection, [<Optional>]_impl: Default1) = (^collection : (static member Rev : _->_) x) : 'collection
static member inline Rev (_: ^t when ^t: null and ^t: struct, _mthd: Default1) = id


Expand All @@ -378,15 +378,15 @@ type Sort =
static member Sort (x: list<'a>, [<Optional>]_impl: Sort) = List.sort x
static member Sort (x: 'a [] , [<Optional>]_impl: Sort) = Array.sort x

static member inline Invoke (source: '``C<'T>``) : '``C<'T>`` =
static member inline Invoke (source: '``Collection<'T>``) : '``Collection<'T>`` =
let inline call_2 (a: ^a, b: ^b) = ((^a or ^b) : (static member Sort : _*_ -> _) b, a)
let inline call (a: 'a, b: 'b) = call_2 (a, b)
call (Unchecked.defaultof<Sort>, source)
static member inline InvokeOnInstance (source: '``C<'T>``) : '``C<'T>`` = (^``C<'T>`` : (static member Sort : _->_) source) : ^``C<'T>``
static member inline InvokeOnInstance (source: '``Collection<'T>``) : '``Collection<'T>`` = (^``Collection<'T>`` : (static member Sort : _->_) source) : ^``Collection<'T>``

static member inline Sort (x: '``Collection<'T>``, [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.sort |> OfSeq.Invoke : '``Collection<'T>``
static member inline Sort (x: '``collection<'T>``, [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.sort |> OfSeq.Invoke : '``collection<'T>``

static member inline Sort (x: ^``Collection<'T>``, [<Optional>]_impl: Default1) = (^``Collection<'T>`` : (static member Sort : _->_) x) : '``Collection<'T>``
static member inline Sort (x: ^``collection<'T>``, [<Optional>]_impl: Default1) = (^``collection<'T>`` : (static member Sort : _->_) x) : '``collection<'T>``
static member inline Sort (_: ^t when ^t: null and ^t: struct, _mthd: Default1) = id


Expand All @@ -396,14 +396,14 @@ type SortBy =
static member SortBy (x: list<'a>, f, [<Optional>]_impl: SortBy) = List.sortBy f x
static member SortBy (x: 'a [] , f, [<Optional>]_impl: SortBy) = Array.sortBy f x

static member inline Invoke (projection: 'T->'Key) (source: '``C<'T>``) : '``C<'T>`` =
static member inline Invoke (projection: 'T->'Key) (source: '``Collection<'T>``) : '``Collection<'T>`` =
let inline call_2 (a: ^a, b: ^b, f) = ((^a or ^b) : (static member SortBy : _*_*_ -> _) b, f, a)
let inline call (a: 'a, b: 'b, f) = call_2 (a, b, f)
call (Unchecked.defaultof<SortBy>, source, projection)
static member inline InvokeOnInstance (projection: 'T->'Key) (source: '``C<'T>``) : '``C<'T>`` = (^``C<'T>`` : (static member SortBy : _*_->_) source, projection) : ^``C<'T>``
static member inline InvokeOnInstance (projection: 'T->'Key) (source: '``Collection<'T>``) : '``Collection<'T>`` = (^``Collection<'T>`` : (static member SortBy : _*_->_) source, projection) : ^``Collection<'T>``

static member inline SortBy (x: '``Collection<'T>``, f , [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.sortBy f |> OfSeq.Invoke : '``Collection<'T>``
static member inline SortBy (x: ^``Collection<'T>``, f , [<Optional>]_impl: Default1) = (^``Collection<'T>`` : (static member SortBy : _*_->_) f, x) : '``Collection<'T>``
static member inline SortBy (x: '``collection<'T>``, f , [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.sortBy f |> OfSeq.Invoke : '``collection<'T>``
static member inline SortBy (x: ^``collection<'T>``, f , [<Optional>]_impl: Default1) = (^``collection<'T>`` : (static member SortBy : _*_->_) f, x) : '``collection<'T>``
static member inline SortBy (_: ^t when ^t: null and ^t: struct, _: 'T->'U, _mthd: Default1) = id

type SortByDescending =
Expand All @@ -412,14 +412,14 @@ type SortByDescending =
static member SortByDescending (x: list<'a>, f, [<Optional>]_impl: SortBy) = List.sortByDescending f x
static member SortByDescending (x: 'a [] , f, [<Optional>]_impl: SortBy) = Array.sortByDescending f x

static member inline Invoke (projection: 'T->'Key) (source: '``C<'T>``) : '``C<'T>`` =
static member inline Invoke (projection: 'T->'Key) (source: '``Collection<'T>``) : '``Collection<'T>`` =
let inline call_2 (a: ^a, b: ^b, f) = ((^a or ^b) : (static member SortByDescending : _*_*_ -> _) b, f, a)
let inline call (a: 'a, b: 'b, f) = call_2 (a, b, f)
call (Unchecked.defaultof<SortByDescending>, source, projection)
static member inline InvokeOnInstance (projection: 'T->'Key) (source: '``C<'T>``) : '``C<'T>`` = (^``C<'T>`` : (static member SortByDescending : _*_->_) source, projection) : ^``C<'T>``
static member inline InvokeOnInstance (projection: 'T->'Key) (source: '``Collection<'T>``) : '``Collection<'T>`` = (^``Collection<'T>`` : (static member SortByDescending : _*_->_) source, projection) : ^``Collection<'T>``

static member inline SortByDescending (x: '``Collection<'T>``, f , [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.sortByDescending f |> OfSeq.Invoke : '``Collection<'T>``
static member inline SortByDescending (x: ^``Collection<'T>``, f , [<Optional>]_impl: Default1) = (^``Collection<'T>`` : (static member SortByDescending : _*_->_) f, x) : '``Collection<'T>``
static member inline SortByDescending (x: '``collection<'T>``, f , [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.sortByDescending f |> OfSeq.Invoke : '``collection<'T>``
static member inline SortByDescending (x: ^``collection<'T>``, f , [<Optional>]_impl: Default1) = (^``collection<'T>`` : (static member SortByDescending : _*_->_) f, x) : '``collection<'T>``
static member inline SortByDescending (_: ^t when ^t: null and ^t: struct, _: 'T->'U, _mthd: Default1) = id

type Split =
Expand Down
8 changes: 4 additions & 4 deletions src/FSharpPlus/Control/Indexable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ type FindSliceIndex =
static member inline InvokeOnInstance (slice: '``Collection<'T>``) (source: '``Collection<'T>``) : 'Index =
(^``Collection<'T>``: (static member FindSliceIndex: _*_->_) source, slice)
static member FindSliceIndex (x: seq<'a> , e , [<Optional>]_impl: Default2) = Seq.findSliceIndex e x
static member inline FindSliceIndex (x: '``C<'T>``, e: '``C<'T>``, _impl: Default1) : 'Index = FindSliceIndex.InvokeOnInstance e x
static member inline FindSliceIndex (x: '``collection<'T>``, e: '``collection<'T>``, _impl: Default1) : 'Index = FindSliceIndex.InvokeOnInstance e x
static member inline FindSliceIndex (_: ^t when ^t: null and ^t: struct, _, _impl: Default1) = ()

static member inline Invoke (slice: '``Collection<'T>``) (source: '``Collection<'T>``) : 'Index =
Expand All @@ -249,7 +249,7 @@ type TryFindSliceIndex =
static member inline InvokeOnInstance (slice: '``Collection<'T>``) (source: '``Collection<'T>``) : 'Index option =
(^``Collection<'T>``: (static member TryFindSliceIndex: _*_->_) source, slice)
static member TryFindSliceIndex (x: seq<'a> , e , [<Optional>]_impl: Default2) = Seq.tryFindSliceIndex e x
static member inline TryFindSliceIndex (x: '``C<'T>``, e: '``C<'T>``, _impl: Default1) : 'Index option = TryFindSliceIndex.InvokeOnInstance e x
static member inline TryFindSliceIndex (x: '``collection<'T>``, e: '``collection<'T>``, _impl: Default1) : 'Index option = TryFindSliceIndex.InvokeOnInstance e x
static member inline TryFindSliceIndex (_: ^t when ^t: null and ^t: struct, _, _impl: Default1) = ()

static member inline Invoke (slice: '``Collection<'T>``) (source: '``Collection<'T>``) : 'Index option =
Expand All @@ -270,7 +270,7 @@ type FindLastSliceIndex =
static member inline InvokeOnInstance (slice: '``Collection<'T>``) (source: '``Collection<'T>``) : 'Index =
(^``Collection<'T>``: (static member FindLastSliceIndex: _*_->_) source, slice)
static member FindLastSliceIndex (x: seq<'a> , e , [<Optional>]_impl: Default2) = Seq.findLastSliceIndex e x
static member inline FindLastSliceIndex (x: '``C<'T>``, e: '``C<'T>``, _impl: Default1) : 'Index = FindLastSliceIndex.InvokeOnInstance e x
static member inline FindLastSliceIndex (x: '``collection<'T>``, e: '``collection<'T>``, _impl: Default1) : 'Index = FindLastSliceIndex.InvokeOnInstance e x
static member inline FindLastSliceIndex (_: ^t when ^t: null and ^t: struct, _, _impl: Default1) = ()

static member inline Invoke (slice: '``Collection<'T>``) (source: '``Collection<'T>``) : 'Index =
Expand All @@ -289,7 +289,7 @@ type TryFindLastSliceIndex =
static member inline InvokeOnInstance (slice: '``Collection<'T>``) (source: '``Collection<'T>``) : 'Index option =
(^``Collection<'T>``: (static member TryFindLastSliceIndex: _*_->_) source, slice)
static member TryFindLastSliceIndex (x: seq<'a> , e , [<Optional>]_impl: Default2) = Seq.tryFindLastSliceIndex e x
static member inline TryFindLastSliceIndex (x: '``C<'T>``, e: '``C<'T>``, _impl: Default1) : 'Index option = TryFindLastSliceIndex.InvokeOnInstance e x
static member inline TryFindLastSliceIndex (x: '``collection<'T>``, e: '``collection<'T>``, _impl: Default1) : 'Index option = TryFindLastSliceIndex.InvokeOnInstance e x
static member inline TryFindLastSliceIndex (_: ^t when ^t: null and ^t: struct, _, _impl: Default1) = ()

static member inline Invoke (slice: '``Collection<'T>``) (source: '``Collection<'T>``) : 'Index option =
Expand Down
Loading