Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Doc vs. Doc'

0 views
Skip to first unread message

Geoffrey Irving

unread,
Sep 6, 2009, 12:11:11 PM9/6/09
to Dylan Alex Simon, duck...@googlegroups.com
Pretty.parens returns Doc instead of PrecDoc, which means sometimes I
have to type an extra pretty'. E.g.,

p :: Either A B -> Doc'
p (Left a) = pretty' a
p (Right b) = pretty' (parens b)

Do we lose anything if we make parens and similar functions return Doc'?

Geoffrey

Dylan Alex Simon

unread,
Sep 6, 2009, 12:37:38 PM9/6/09
to Geoffrey Irving, duck...@googlegroups.com
From Geoffrey Irving <irv...@naml.us>, Sun, Sep 06, 2009 at 12:11:11PM -0400:

I did it that way because, more often than not, you shouldn't be using parens
directly, but rather (#>). For example, in your case if Right is really
always supposed to be parenthesized, you can say it has precedence -1:

p :: Either A B -> Doc'
p (Left a) = pretty' a

p (Right b) = -1 #> b

But if you really want to make parens PrecDoc and ignore its precedence,
that's fine too.

:-Dylan

Geoffrey Irving

unread,
Sep 6, 2009, 12:39:13 PM9/6/09
to Geoffrey Irving, duck...@googlegroups.com

Ah, that makes sense. I only ran it into the problem because I was
printing out Haskell code (yes, I started implementing (3)), so we can
leave it the way it is.

Geoffrey

Reply all
Reply to author
Forward
0 new messages