ppr of HsDo

Alan & Kim Zimmerman alan.zimm at gmail.com
Thu Nov 10 10:06:36 UTC 2016


For context, I am putting in a test suite similar to the one for
ghc-exactprint to ensure that the pretty printer always generates code that
can be round tripped back to the original AST.

This means that fears of some uncaught case requiring us do it the
guaranteed safe way should be allayed.

In the process I am updating the pretty printer.

So the question really is, given the existence of that test suite, what
style of code should we have in our messages, and in pretty printed code?

Alan


On Thu, Nov 10, 2016 at 12:02 PM, Simon Peyton Jones <simonpj at microsoft.com>
wrote:

>
>
> It’s not about GHC’s programming style, is it?  It’s about what the
> pretty-printer does.  If it were me I’d use braces and semicolons
> everywhere, so that I could guarantee to parse it easily.
>
>
>
> But that’s not a strong opinion and I would willingly yield to others!
>
>
>
> Simon
>
>
>
> *From:* Alan & Kim Zimmerman [mailto:alan.zimm at gmail.com]
> *Sent:* 10 November 2016 08:31
> *To:* Simon Peyton Jones <simonpj at microsoft.com>
> *Cc:* ghc-devs at haskell.org
> *Subject:* Re: ppr of HsDo
>
>
>
> Thanks.
>
> And any thoughts on my proposal to do away with the braces/semi
> completely?  I suspect GHC is the only significant body of code that uses
> that style still.
>
> Alan
>
>
>
> On Thu, Nov 10, 2016 at 10:24 AM, Simon Peyton Jones <
> simonpj at microsoft.com> wrote:
>
> I think it’s because the  “;” is treated as part of the let not part of
> the do.  After all, how does the implicit layout of the let know that the
> let-bindings are finished?
>
>
>
> This should work
>
>
>
> foo
>   = do { let { x = 1 };
>          Just 5 }
>
>
>
> Now the let bindings are clearly brought to an end.  Or this
>
>
>
> foo
>   = do { let x = 1
>
>        ; Just 5 }
>
>
>
> Now the “’;” is to the left of the x=1 and so brings the let’s implicit
> layout to an end.
>
>
>
> But not this!
>
>
>
> foo
>   = do { let x = 1; Just 5 }
>
>
>
> So it’s a bug in the pretty-printer, not the parser
>
>
>
> SImon
>
>
>
>
>
> *From:* ghc-devs [mailto:ghc-devs-bounces at haskell.org] *On Behalf Of *Alan
> & Kim Zimmerman
> *Sent:* 10 November 2016 07:01
> *To:* ghc-devs at haskell.org
> *Subject:* ppr of HsDo
>
>
>
> The pretty printer turns
>
> foo = do
>   let x = 1
>   Just 5
>
> into
>
> foo
>   = do { let x = 1;
>          Just 5 }
>
> which does not parse, complaining about "parse error on input ‘Just’"
>
> Is this a parser error or a ppr problem?  I am keen to fix the ppr to
> output
>
>
> foo
>   = do let x = 1
>        Just 5
>
> but I am not sure if there is a parser bug too.
>
> Alan
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20161110/f0f23651/attachment-0001.html>


More information about the ghc-devs mailing list