Skip to content

Commit

Permalink
Update access control to clarify accessibility for DU cases and recor…
Browse files Browse the repository at this point in the history
…d labels. (dotnet#7221)
  • Loading branch information
cartermp authored Aug 23, 2018
1 parent d27bbb1 commit 2fae856
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions docs/fsharp/language-reference/access-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ ms.date: 05/16/2016

*Access control* refers to declaring which clients can use certain program elements, such as types, methods, and functions.


## Basics of Access Control
In F#, the access control specifiers `public`, `internal`, and `private` can be applied to modules, types, methods, value definitions, functions, properties, and explicit fields.


- `public` indicates that the entity can be accessed by all callers.

- `internal` indicates that the entity can be accessed only from the same assembly.

- `private` indicates that the entity can be accessed only from the enclosing type or module.


>[!NOTE]
The access specifier `protected` is not used in F#, although it is acceptable if you are using types authored in languages that do support `protected` access. Therefore, if you override a protected method, your method remains accessible only within the class and its descendents.

Expand All @@ -28,17 +25,14 @@ If no access specifier is used, the default is `public`, except for `let` bindin

Signatures in F# provide another mechanism for controlling access to F# program elements. Signatures are not required for access control. For more information, see [Signatures](signatures.md).


## Rules for Access Control
Access control is subject to the following rules:


- Inheritance declarations (that is, the use of `inherit` to specify a base class for a class), interface declarations (that is, specifying that a class implements an interface), and abstract members always have the same accessibility as the enclosing type. Therefore, an access control specifier cannot be used on these constructs.

- Individual cases in a discriminated union cannot have their own access control modifiers separate from the union type.

- Individual fields of a record type cannot have their own access control modifiers separate from the record type.
- Accessibility for individual cases in a discriminated union is determined by the accessibility of the discriminated union itself. That is, a particular union case is no less accessible than the union itself.

- Accessibility for individual fields of a record type cannot is determined by the accessibility of the record itself. That is, a particular record label is no less accessible than the record itself.

## Example
The following code illustrates the use of access control specifiers. There are two files in the project, `Module1.fs` and `Module2.fs`. Each file is implicitly a module. Therefore, there are two modules, `Module1` and `Module2`. A private type and an internal type are defined in `Module1`. The private type cannot be accessed from `Module2`, but the internal type can.
Expand Down

0 comments on commit 2fae856

Please sign in to comment.