Hello,


thinking about whether the pretty printer proposed by Wadler requires
some changes to be efficient in a strict language, I stumbled over the
the last case defining `flatten':

        flatten (x :<|> y) = flatten x

I wonder why it is necessary here to recurse on x. The only point were a
doc (x:<|>y) is constructed is in the function `group':

        group z   = flatten z :<|> z

So the x above is always flat already. Wouldn't the equation

        flatten (x :<|> y) = x

suffice? Doing recursion here seems to be unnecessary overhead. In
particular, it prevents structure sharing between alternatives when
grouping, because flatten rebuilds the whole doc tree (which might be
more of a problem without laziness).

Am I missing something?


        - Andreas


Reply via email to