From ad716d76f51a4dc9d5cdcb8b27fbcf78eaf78f9c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Oct 2025 13:35:46 +0000 Subject: [PATCH 1/4] Initial plan From 32c9dd492455ff9abbc09d2f527a1cc5ca8944cc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Oct 2025 13:45:26 +0000 Subject: [PATCH 2/4] Add F# pattern spacing guidelines for consistency with expressions Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/fsharp/style-guide/formatting.md | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/fsharp/style-guide/formatting.md b/docs/fsharp/style-guide/formatting.md index 927ba4411270d..86785a7e71bcf 100644 --- a/docs/fsharp/style-guide/formatting.md +++ b/docs/fsharp/style-guide/formatting.md @@ -245,6 +245,17 @@ SomeClass.Invoke () String.Format (x.IngredientName, x.Quantity) ``` +These same formatting conventions apply to pattern matching. Consistency between expressions and patterns is highly valued in F# style: + +```fsharp +// ✔️ OK - Consistent formatting for expressions and patterns +let result = Some(value) + +match result with +| Some(x) -> x +| None -> 0 +``` + You may need to pass arguments to a function on a new line as a matter of readability or because the list of arguments or the argument names are too long. In that case, indent one level: ```fsharp @@ -1152,6 +1163,25 @@ match l with | [] -> failwith "Couldn't find David" ``` +Pattern matching formatting should be consistent with expression formatting. Do not add a space before the opening parenthesis of pattern arguments: + +```fsharp +// ✔️ OK +match x with +| Some(y) -> y +| None -> 0 + +// ✔️ OK +match data with +| Success(value) -> value +| Error(msg) -> failwith msg + +// ❌ Not OK, pattern formatting should match expression formatting +match x with +| Some (y) -> y +| None -> 0 +``` + If the expression on the right of the pattern matching arrow is too large, move it to the following line, indented one step from the `match`/`|`. ```fsharp From 368c71a793fbc6c1d4f27212eec5de14604e729d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Oct 2025 13:50:51 +0000 Subject: [PATCH 3/4] Add clarification for curried arguments in patterns Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/fsharp/style-guide/formatting.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/fsharp/style-guide/formatting.md b/docs/fsharp/style-guide/formatting.md index 86785a7e71bcf..6a8ff1213931e 100644 --- a/docs/fsharp/style-guide/formatting.md +++ b/docs/fsharp/style-guide/formatting.md @@ -1182,6 +1182,18 @@ match x with | None -> 0 ``` +However, do use spaces between separate curried arguments in patterns, just as in expressions: + +```fsharp +// ✔️ OK - space between curried arguments +match x with +| Pattern arg (a, b) -> processValues arg a b + +// ❌ Not OK - missing space between curried arguments +match x with +| Pattern arg(a, b) -> processValues arg a b +``` + If the expression on the right of the pattern matching arrow is too large, move it to the following line, indented one step from the `match`/`|`. ```fsharp From bf42e7045ac64e1801e86844cd01e19084182455 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Wed, 8 Oct 2025 09:06:12 -0400 Subject: [PATCH 4/4] Update docs/fsharp/style-guide/formatting.md --- docs/fsharp/style-guide/formatting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fsharp/style-guide/formatting.md b/docs/fsharp/style-guide/formatting.md index 6a8ff1213931e..a78f48945aad8 100644 --- a/docs/fsharp/style-guide/formatting.md +++ b/docs/fsharp/style-guide/formatting.md @@ -245,7 +245,7 @@ SomeClass.Invoke () String.Format (x.IngredientName, x.Quantity) ``` -These same formatting conventions apply to pattern matching. Consistency between expressions and patterns is highly valued in F# style: +These same formatting conventions apply to pattern matching. F# style values consistent formatting: ```fsharp // ✔️ OK - Consistent formatting for expressions and patterns