Skip to content

Documentation contains invalid type extension for seq<'T> which is a type abbreviation #1670

@abelbraaksma

Description

@abelbraaksma

The documentation about type extensions contains the following example code:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions