quchen / prettyprinter

A modern, extensible and well-documented prettyprinter.
BSD 2-Clause "Simplified" License
293 stars 34 forks source link

Terminal.renderLazy isn't lazy #175

Closed georgefst closed 4 years ago

georgefst commented 4 years ago

This originally came up in discussion at cdepillabout/pretty-simple#67. Although it returns a lazy Text, there doesn't really seem to be any laziness in Data.Text.Prettyprint.Doc.Render.Terminal.renderLazy, presumably due to the use of ST.

For example, I would expect to see:

(TL.take 5 . renderLazy . fix $ SChar 'a') == "aaaaa"

but instead the left-hand-side is just .

I could submit a PR fixing this, since I've already written the code (though I haven't benchmarked it...).

sjakobi commented 4 years ago

While I do feel hat pretty-simple is a bit of an outlier with its laziness requirement, I agree that it would be nice if the renderLazy output could be consumed in a streaming fashion.

The function is somewhat performance sensitive though. See e.g. https://github.com/quchen/prettyprinter/issues/121. So I hope we can keep the performance within 20% or so of the current implementation.

I think I'd also slightly prefer not to use monad transformers in the implementation, if that's possible.