Description
When I continue piping at the proper level of indentation after a match expression with case results specified on separate lines, the compiler sometimes apparently interprets my following code as applying to the last case of the match rather than to the whole.
This example function
let foo a =
match a with
| true ->
(+)
| false ->
(-)
<| 1
is apparently equivalent to
let foo a =
match a with
| true -> (+)
| false -> (-) <| 1
rather than to
let foo a =
(match a with
| true ->
(+)
| false ->
(-))
<| 1
Expected behavior
val foo: bool -> int -> int
with the returned value incremented by one if the bool
argument is true
or decremented by one otherwise.
Actual behavior
The (-)
function shows this compiler error: The type ''a -> 'b' does not match the type 'int'
. Further, foo
appears neither to have a type signature nor to be defined thereafter in the code.
I would expect this behavior had I indented the last line differently:
let foo a =
match a with
| true ->
(+)
| false ->
(-)
<| 1
Known workarounds
Add the code following the expression to each case individually.