Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Pipeline following certain matches with cases on new lines does not depend on indentation #12422

Closed
@LyndonGingerich

Description

@LyndonGingerich

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions