Skip to content

Clarify placement of function keyword #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Smaug123
Copy link
Contributor

Fixes #27. Also an unrelated drive-by correction of a misaligned function keyword.

@Smaug123 Smaug123 changed the title Clarify placement of keyword Clarify placement of function keyword May 19, 2021
@rdipardo
Copy link

A suggestion for a small addendum: demonstrate a pattern match using a direct pipe into function, like this example:

[ 'a'; 'b'; 'c' ]
|> List.tryFind (fun c -> c = 'c')
|> function
| Some c -> c
| None -> 'd'

I've probably missed something, but I haven't been able to find explicit guidance on whether option branches following |> function should be indented or aligned with the keyword as in a match _ with construct.

Consider this illustration of piping into match:

let bar =
    baz
    |> (
        match false with
        | true -> id
        | false -> id
    )

If baz were applied to function instead, one might expect the branches to be indented no farther than the keyword, as above. However, it matters to fantomas whether the expression is parenthesized:

Code

let bar =
    baz
    |> (
        function
        | true -> id
        | false -> id
    )

Result

let bar =
    baz
    |> (function
    | true -> id
    | false -> id)

Remove the parentheses, and the matches receive extra indentation as in a multiline lambda (on which the published guide already gives advice regarding indentation):

let bar =
    baz
    |> function
        | true -> id
        | false -> id

I may just be sounding off here (indeed, I've been told so already), but my intuition is that the accepted style of match _ with (no indent) might as well apply to |> function when they're syntactically and functionally equivalent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parenthesis placement when match is applied with infix operator
2 participants