From f0bf252ec90be87e767f06608fe0ee3ed8ef2569 Mon Sep 17 00:00:00 2001 From: Vladimir Shchur Date: Sun, 5 May 2024 23:04:39 +0300 Subject: [PATCH] Added clarification for match expression multiline case Discussed and approved in https://github.com/fsharp/fslang-design/issues/650 --- docs/fsharp/style-guide/formatting.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/fsharp/style-guide/formatting.md b/docs/fsharp/style-guide/formatting.md index 310c282a30d6d..fb2f80a49d681 100644 --- a/docs/fsharp/style-guide/formatting.md +++ b/docs/fsharp/style-guide/formatting.md @@ -1092,16 +1092,24 @@ match l with | [] -> failwith "Couldn't find David" ``` -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`/`|`. +If one of the expressions on the right of the pattern matching arrow is too large, move it to the following line, indented one step from the `match`/`|`. Move all the other expressions to the next line as well for consistency. ```fsharp // ✔️ OK match lam with -| Var v -> 1 +| Var v -> + 1 | Abs(x, body) -> 1 + sizeLambda body | App(lam1, lam2) -> sizeLambda lam1 + sizeLambda lam2 + +// ❌ Not OK, see above for preferred formatting +match lam with +| Var v -> 1 +| Abs(x, body) -> 1 + sizeLambda body +| App(lam1, lam2) -> + sizeLambda lam1 + sizeLambda lam2 ``` Similar to large if conditions, if a match expression is multiline or exceeds the default tolerance of the single-line, the match expression should use one indentation and a new line.