Skip to content

F# Records documentation doesn't have information on constructor accessibility modifiers #48480

@zakharsmirnoff

Description

@zakharsmirnoff

Type of issue

Missing information

Description

Neither of Microsoft official docs have mentions on one of the important features of records: their constructors can have accessibility modifiers. For example:

module Example =
    type Example =
        private {
            Property: string
        }

module TryCreate =
    open Example
    let example = {Property = "failure"} // compile error: The union cases or fields of the type 'Example' are not accessible from this code location

I think this is a very important feature which makes private or internal constructors accessible to users, thus along with type extensions emulating almost all features of classes, so users can use records instead of resorting right away to classes.

Therefore, the documentation should mention this in syntax:

[ attributes ]
type [accessibility-modifier] typename = 
    [accessibility-modifier] { [ mutable ] label1 : type1;
      [ mutable ] label2 : type2;
      ... }
    [ member-list ] 

It would be nice to have examples and explanations on that in the article as well.

Page URL

https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/records

Content source URL

https://github.com/dotnet/docs/blob/main/docs/fsharp/language-reference/records.md

Document Version Independent Id

76d64ebf-a460-3e86-898f-c31c6c70e354

Platform Id

10b5f725-1a90-d7dc-9f4e-18f86dd7ef6b

Article author

@BillWagner

Metadata

  • ID: fe1bc735-dea5-eaf1-8adf-6fa03a43a88e
  • PlatformId: 10b5f725-1a90-d7dc-9f4e-18f86dd7ef6b
  • Service: dotnet-fsharp

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions