fsharp / fsharp/fslang-suggestions
Implicit way to 'RequireQualifiedAccess' for all defined DUs
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
I propose we make it possible to implicitly require qualified access for all DUs declared in a project.
The existing way of approaching this problem in F# is to add an attribute ([<RequireQualifiedAccess>]) to every DU.
Often a lot if not all DUs are annotated with the [<RequireQualifiedAccess>] attribute. This adds a lot of noise that would not be required with this proposal.
(Example of how distracting RequireQualifiedAccess everywhere is)
[<RequireQualifiedAccess>]
type InstructionStepFormError =
| TitleIsRequired
| ShortDescriptionIsRequired
| LongDescriptionIsRequired
[<RequireQualifiedAccess>]
type InstructionDocumentFormError =
| Steps of Map<Guid, InstructionStepFormError list>
| AtLeastOneStepRequired
[<RequireQualifiedAccess>]
type InstructionMetaFormError =
| AtLeastOneOwner
| AtLeastOneEquipment
| TitleIsRequired
| TitleAlreadyExists
[<RequireQualifiedAccess>]
type CreateInstructionFormError =
| Meta of InstructionMetaFormError list
| Document of InstructionDocumentFormError list
This could be enabled in the Project file.
It would also require an escape hatch for when qualified access should not be required. I would propose to change the RequireQualifiedAccessAttribute so it has 2 constructors.
-
[<RequireQualifiedAccess>]-> same as[<RequireQualifiedAccess true>] -
[<RequireQualifiedAccess true>] -
[<RequireQualifiedAccess false>]
Pros and Cons
The advantages of making this adjustment to F# are ...
- removes noise
- allows developers/teams to choose their defaults
The disadvantages of making this adjustment to F# are ...
- code is not valid on its own, context is needed to know if qualified access is required.
- makes things more complicated
Extra information
Estimated cost (XS, S, M, L, XL, XXL): ?
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
- This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
- I have searched both open and closed suggestions on this site and believe this is not a duplicate
- This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
Please tick all that apply:
- This is not a breaking change to the F# language design
- I or my company would be willing to help implement and/or test this (If provided with guidance and a lot of time)
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the proposal and its 16-comment discussion, then review how the project file and RequireQualifiedAccessAttribute are currently defined. The work is done only when the language-design questions are resolved and the chosen project-wide behavior and opt-out mechanism are specified well enough for implementation and tests.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100