Skip to content
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

How to deal with multiline expressions in parens #12

Closed
avh4 opened this issue Oct 20, 2015 · 7 comments
Closed

How to deal with multiline expressions in parens #12

avh4 opened this issue Oct 20, 2015 · 7 comments

Comments

@avh4
Copy link
Owner

avh4 commented Oct 20, 2015

How should the following be formatted?

foo x =
    ( case x of
        Just a ->
            a
        _ ->
            7
    )
        |> toString
@avh4 avh4 added this to the MVP milestone Oct 20, 2015
@Apanatshka
Copy link

I'm pretty sure the offside rule allows you to write this without the round brackets... Something like:

foo x =
    case x of
        Just a ->
            a
        _ ->
            7
    |> toString

I prefer my pipelines aligned, rather than indented anyway.

@avh4
Copy link
Owner Author

avh4 commented Oct 20, 2015

This isn't exactly it, but I think there must be cases where the parens are required:

foo x =
    CtorWithTwoParams
        ( case x of
            Just a ->
                a
            _ ->
                7
        )
        "second param"

@Apanatshka
Copy link

Yes, a case as a parameter will need to be wrapped in parentheses I guess. I'm ok this the style from your example. You simply shouldn't use case expressions there, so the formatter punishes you by giving an ugly piece of code (that's still very readable).

@rtfeldman
Copy link

Following this proposed rule, all I'd change would be removing the space after the open paren:

foo x =
    (case x of
        Just a ->
            a
        _ ->
            7
    )
        |> toString

Neither of them looks great, but this has the benefit of the rule being simpler to explain. 😉

@avh4
Copy link
Owner Author

avh4 commented Oct 20, 2015

Using no space leads to:

multilineParenthesizedExpressions =
    (if range == 0 then
        0.1
      else
        toFloat range
    )

where the if and else are not aligned!

@rtfeldman
Copy link

Following this idea would solve this too:

foo x =
    (
        case x of
            Just a ->
                a

            _ ->
                7
    )
        |> toString

@avh4
Copy link
Owner Author

avh4 commented Oct 26, 2015

We'll go with #20 for now. The it ended up working, the following case will actually keep if and else aligned:

multilineParenthesizedExpressions =
    (if range == 0 then
        0.1
     else
        toFloat range
    )

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

No branches or pull requests

3 participants