"value...">

What match does the indentation rule play here?

This indentation works fine:

match 5 with
| k when k < 0 ->
  "value is negative"
| k -> "value is non-negative"
|> printfn "%s"

but this is not so:

match 5 with
| k when k < 0 ->
  "value is negative"
| k ->
  "value is non-negative"
|> printfn "%s"

What indentation rule F # is in the game?

+6
source share
1 answer

This is a combination of indentation matchand a special case for operators.

First, underneath match, the body of each case can begin as far as possible from the vertical line. For example, this works:

match 5 with
| x ->
"some value"

Secondly, there is a special offset rule for operators that appear at the beginning of a new line: such operators can be located to the left of the previous line to the width of the operator plus one, For example, they all work the same way:

let x =
    "abc"
    |> printf "%s"

let y =
       "abc"
    |> printf "%s"

let z =
 "abc"
    |> printf "%s"

, match printfn, .

enter image description here

"value is non-negative" , , printfn .

match 5 with
| k when k < 0 ->
  "value is negative"
| k ->
    "value is non-negative"
|> printfn "%s"

5 , .

+6

All Articles