Pretty.lhs: bug found, feature missed

Johannes Waldmann joe@isun.informatik.uni-leipzig.de
Tue, 6 Nov 2001 22:40:06 +0100 (MET)


We were recently bitten by what seems to be 
a bug in hslibs/text/Pretty.lhs.
The following code prints an infinite string:


import Pretty

ncat x y = nest 4 $ cat [ x, y ]
d1 = foldl1 ncat $ take 50 $ repeat $ char 'a'
d2 = parens $  sep [ d1, text "+" , d1 ]
main = print d2


I think this is due to the function indent/spaces
called with a negative argument.  The following is in Pretty.lhs:


indent n | n >= 8 = '\t' : indent (n - 8)
         | otherwise      = spaces n

spaces 0 = ""
spaces n       = ' ' : spaces (n - 1)


This looks Really Dangerous. 



Another point: we would want to use a version of `render (d :: Doc)' 
that always produces only a bounded amount of output,
by cutting off sub-documents that are too deeply nested.
(Some LISP pretty printers do have this feature -
they cut long lists, and deeply nested lists).
Before sitting down and trying to implement this, we would like to
check whether someone already did it. If so, please tell us.


Best regards,
-- 
-- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ --
-- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/252 --