Skip to content

Commit

Permalink
Added clarification for match expression multiline case
Browse files Browse the repository at this point in the history
Discussed and approved in fsharp/fslang-design#650
  • Loading branch information
Lanayx committed May 5, 2024
1 parent 5152fdb commit f0bf252
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docs/fsharp/style-guide/formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f0bf252

Please sign in to comment.