Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added RFC-1334-elif:
F# RFC FS-1334 - Add
#elifPreprocessor DirectiveSummary
Add
#elifto F# conditional compilation so multiple mutually exclusive branches can be written linearly (#if ... #elif ... #elif ... #else ... #endif) instead of nesting or repeating#ifblocks. Aligns F# with C# and other languages; improves readability.Motivation
Without
#elif, developers either:#ifinside#else(deep indentation, harder to scan), or#ifblocks plus a final negated catch-all (#if !A && !B && !C), which is verbose and error-prone.#elifremoves redundancy, reduces logical mistakes, and eases cross-language sharing.Design
Grammar change:
First matching condition’s group is included; at most one group is compiled.
#elifmust follow an#ifand precede an optional#else. No change to symbol definition semantics.Example #1
Example #2
Spec Changes
Update conditional compilation section to:
{ #elif pp-expression group }to grammar.#elifafter#else,#elifwithout#if, missing condition.Drawbacks
Small parser/editor updates (fantomas, etc); possibility of long chains (already possible).
Alternatives
Keep nesting; use multiple guarded blocks; introduce more complex compile-time constructs (unnecessary).
Prior Art
VB.NET, C/C++, C#, Swift, Objective-C all support
#elif(or equivalent). Aligns F# with ecosystem norms.Compatibility
Non-breaking. Older compilers will error on
#elif. No IL or FSharp.Core changes.Diagnostics
Errors for:
#elifwithout preceding#if#elifafter#elseTooling
Add keyword highlighting (or darken un-used branch), folding across entire block, completion for
#elif. No runtime tooling differences.Performance
Negligible; linear evaluation of conditions. No impact on generated code beyond selected branch.
Scaling
Typical branch count ≤ 8; acceptable upper bound ≈ 50; linear processing.
Migration Example
Before:
After: