[Haskell-cafe] Layout rules for if then else

Andrew Gibiansky andrew.gibiansky at gmail.com
Tue Mar 10 18:05:41 UTC 2015


Just to be clear, I *think* layout rules don't apply here at all, actually.

If I understand correctly, "layout" has to do with turning spacing into
braces and semicolons. A new line is a semicolon. A brace group is inserted
around things that are aligned where a brace group actually makes sense.

e.g.

let x = y
    y = z
  in ...

gets turned into roughly

let { x = y
    ; y = z
    } in ...

if-then-else however is just an expression, like a ternary operator, so it
doesn't need any semicolons or braces. So layout is unrelated, except for
the issue of `do` blocks inserting semicolons into `if-then-else` groups
(and that's what DoAndIfThenElse fixes).

-- Andrew

PS. I am very glad someone is working on ghc-exactprint. It's a really
important step in developing better Haskell tooling, imho. Doing that sort
of thing right now with haskell-src-exts right now is a real pain (see half
of the closed issues on hindent... about how it doesn't preserve formatting
in many places.)

On Tue, Mar 10, 2015 at 9:25 AM, Alan & Kim Zimmerman <alan.zimm at gmail.com>
wrote:

> Ok, adding a do does make a difference. More complexity.
>
> Thanks
>   Alan
>
> On Tue, Mar 10, 2015 at 6:06 PM, Brandon Allbery <allbery.b at gmail.com>
> wrote:
>
>> On Tue, Mar 10, 2015 at 12:01 PM, Alan & Kim Zimmerman <
>> alan.zimm at gmail.com> wrote:
>>
>>> I am working on ghc-exactprint, and need to flag points where layout
>>> must be preserved, and considering the `if` statement.
>>>
>>> My understanding of the layout rules for if then else is that the `then`
>>> has to start more to the right than the `if`.
>>>
>>
>> I believe you are looking for DoAndIfThenElse.
>>
>> --
>> brandon s allbery kf8nh                               sine nomine
>> associates
>> allbery.b at gmail.com
>> ballbery at sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150310/4123eb5b/attachment.html>


More information about the Haskell-Cafe mailing list