You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documentation contains invalid type extension for seq<'T> which is a type abbreviation #1670
type seq<’T> with
/// Repeat each element of the sequence n times
member xs.RepeatElements(n: int) =
seq { for x in xs do for i in 1 .. n do yield x }
This example code won't compile, it will throw:
error FS0964: Type abbreviations cannot have augmentations
and
error FS0895: Type abbreviations cannot have members
The proper code would be (assuming System.Collections.Generic is opened)
type IEnumerable<'T> with
/// Repeat each element of the sequence n times
member xs.RepeatElements(n: int) =
seq { for x in xs do for i in 1 .. n do yield x }
Note that the text itself mentions that type abbreviations cannot be extended.
@dsyme, yes, I'll look into that (never worked with github sources before). I'm wondering though if my suggested change is a good one. Having type IEnumerable<'T> with... does not append the new method to Seq, because Seq is a module and modules cannot be extended (unfortunately so, but that's a different discussion).
Creating a type Seq = ... would do what you'd expect, but that is not a type extension.
What the code does is (of course) creating an instance member extension for sequences, but that's hardly idiomatic. Perhaps the whole suggestion should go and a different extension that's more fsharpish should be used instead? Any ideas?
Activity
dsyme commentedon Oct 27, 2016
@abelbraaksma Please fix by making a PR to the docs directly?
dsyme commentedon Oct 27, 2016
See dotnet/docs#1178
abelbraaksma commentedon Oct 27, 2016
@dsyme, yes, I'll look into that (never worked with github sources before). I'm wondering though if my suggested change is a good one. Having
type IEnumerable<'T> with...does not append the new method toSeq, becauseSeqis a module and modules cannot be extended (unfortunately so, but that's a different discussion).Creating a
type Seq = ...would do what you'd expect, but that is not a type extension.What the code does is (of course) creating an instance member extension for sequences, but that's hardly idiomatic. Perhaps the whole suggestion should go and a different extension that's more fsharpish should be used instead? Any ideas?
Fix extension docs (#1178)
Sync (#1)