-----------------------------------------------------------
-- renderCompact: renders documents without indentation
--  fast and fewer characters output, good for machines
-----------------------------------------------------------
renderCompact :: Doc -> SimpleDoc
renderCompact x
    = scan 0 [x]
    where
      scan k []     = SEmpty
      scan k (d:ds) = case d of
                        Empty       -> scan k ds
                        Char c      -> let k' = k+1 in seq k' (SChar 0 c (scan k' ds))
                        Text l s    -> let k' = k+l in seq k' (SText 0 l s (scan k' ds))
                        Line _      -> SLine 0 (scan 0 ds)
                        Cat x y     -> scan k (x:y:ds)
                        Nest j x    -> scan k (x:ds)
                        Union x y   -> scan k (y:ds)
                        Column f    -> scan k (f k:ds)
                        Nesting f   -> scan k (f 0:ds)
                        Colored f c x-> SColorOpen f c (scan k (x : ColoredEnd : ds))  
                        ColoredEnd   -> SColorClose (scan k ds)

-----------------------------------------------------------
-- Displayers:  displayS and displayIO
-----------------------------------------------------------
renderCompact :: Doc -> SimpleDoc
renderCompact x
    = scan 0 [x]
    where
      scan k []     = SEmpty
      scan k (d:ds) = case d of
                        Empty       -> scan k ds
                        Char c      -> let k' = k+1 in seq k' (SChar 0 c (scan k' ds))
                        Text l s    -> let k' = k+l in seq k' (SText 0 l s (scan k' ds))
                        Line _      -> SLine 0 (scan 0 ds)
                        Cat x y     -> scan k (x:y:ds)
                        Nest j x    -> scan k (x:ds)
                        Union x y   -> scan k (y:ds)
                        Column f    -> scan k (f k:ds)
                        Nesting f   -> scan k (f 0:ds)
                        Colored f c x-> SColorOpen f c (scan k (x : ColoredEnd : ds))  
                        ColoredEnd   -> SColorClose (scan k ds)

-----------------------------------------------------------
-- Displayers:  displayS and displayIO
-----------------------------------------------------------
renderCompact x
    = scan 0 [x]
    where
      scan k []     = SEmpty
      scan k (d:ds) = case d of
                        Empty       -> scan k ds
                        Char c      -> let k' = k+1 in seq k' (SChar 0 c (scan k' ds))
                        Text l s    -> let k' = k+l in seq k' (SText 0 l s (scan k' ds))
                        Line _      -> SLine 0 (scan 0 ds)
                        Cat x y     -> scan k (x:y:ds)
                        Nest j x    -> scan k (x:ds)
                        Union x y   -> scan k (y:ds)
                        Column f    -> scan k (f k:ds)
                        Nesting f   -> scan k (f 0:ds)
                        Colored f c x-> SColorOpen f c (scan k (x : ColoredEnd : ds))  
                        ColoredEnd   -> SColorClose (scan k ds)

-----------------------------------------------------------
-- Displayers:  displayS and displayIO
-----------------------------------------------------------