wl-pprint-text 1.0.0.0 → 1.2.0.2
raw patch · 5 files changed
Files
- Changelog.md +89/−0
- README.md +8/−0
- Text/PrettyPrint/Leijen/Text.hs +179/−99
- Text/PrettyPrint/Leijen/Text/Monadic.hs +204/−179
- wl-pprint-text.cabal +26/−6
+ Changelog.md view
@@ -0,0 +1,89 @@+1.2.0.2 (2022-01-09)+====================++* Dependency bumps.++1.2.0.1 (2020-01-28)+====================++* Dependency bumps.++1.2.0.0 (2018-05-07)+====================++* Remove `IsString (m Doc)` instance (#16).++* Export the `beside` function from both modules.++ - For non-Monadic pretty-printing this is identical to the+ Semigroup/Monoid `<>` combinator.++ - For Monadic pretty-printing this is the lifted version of `<>`.++* No longer export `<>`. Use `beside` instead, or the+ Semigroup/Monoid instance (for non-Monadic).++1.1.1.1 (2018-04-13)+====================++* Support for GHC-8.4.1.++1.1.1.0 (2017-01-26)+====================++* Support strict `Text` values (thanks to Elliot Cameron).++* Loosened constraints from `Monad` to `Functor` where applicable+ (thanks to Elliot Cameron).++* Uses `base-compat` to make it easier to support multiple GHC+ versions.++* Add `isEmpty :: Doc -> Bool`.++* Support `Semigroup` in `base >= 4.9.0.0`.++1.1.0.4 (2015-04-06)+====================++* Support `GHC-7.10`.++1.1.0.3 (2014-12-24)+====================++* Support `text-1.2.*`.++1.1.0.2 (2014-01-16)+====================++* Support `text-1.1.0.0`.++1.1.0.1 (2013-12-23)+====================++_This probably should have been 1.1.1.0._++* Documentation fixes.++* Add `displayB`, `spacebreak` and `<++>`.++* Smarter treatment of spaces, newlines, etc. (including how `line`+ behaves in `renderOneLine`).++1.1.0.0 (2012-08-22)+====================++* `Doc` is now an instance of `Monoid`.++* Add `renderOneLine` function.++* Add `IsString` instances.++* Make `SimpleDoc` an instance of `Show` for convenience.++* Make the `Show` instance for `Doc` match the documentation.++1.0.0.0 (2012-05-22)+====================++* Initial version,
+ README.md view
@@ -0,0 +1,8 @@+wl-pprint-text+==============++[](https://hackage.haskell.org/package/wl-pprint-text) [](https://travis-ci.org/ivan-m/wl-pprint-text)++A clone of [wl-pprint](http://hackage.haskell.org/package/wl-pprint)+for use with the [text](http://hackage.haskell.org/package/text)+library (with some improved handling of whitespace).
Text/PrettyPrint/Leijen/Text.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- | -- Module : Text.PrettyPrint.Leijen.Text@@ -69,25 +70,25 @@ Doc, -- * Basic combinators- empty, char, text, (<>), nest, line, linebreak, group, softline,- softbreak,+ empty, isEmpty, char, text, textStrict, beside, nest, line, linebreak, group,+ softline, softbreak, spacebreak, -- * Alignment --- -- The combinators in this section can not be described by Wadler's- -- original combinators. They align their output relative to the- -- current output position - in contrast to @nest@ which always- -- aligns to the current nesting level. This deprives these- -- combinators from being \`optimal\'. In practice however they- -- prove to be very useful. The combinators in this section should- -- be used with care, since they are more expensive than the other- -- combinators. For example, @align@ shouldn't be used to pretty- -- print all top-level declarations of a language, but using @hang@- -- for let expressions is fine.+ -- | The combinators in this section can not be described by Wadler's+ -- original combinators. They align their output relative to the+ -- current output position - in contrast to @nest@ which always+ -- aligns to the current nesting level. This deprives these+ -- combinators from being \`optimal\'. In practice however they+ -- prove to be very useful. The combinators in this section should+ -- be used with care, since they are more expensive than the other+ -- combinators. For example, @align@ shouldn't be used to pretty+ -- print all top-level declarations of a language, but using @hang@+ -- for let expressions is fine. align, hang, indent, encloseSep, list, tupled, semiBraces, -- * Operators- (<+>), (<$>), (</>), (<$$>), (<//>),+ (<+>), (<++>), (<$>), (</>), (<$$>), (<//>), -- * List combinators hsep, vsep, fillSep, sep, hcat, vcat, fillCat, cat, punctuate,@@ -103,7 +104,7 @@ squote, dquote, semi, colon, comma, space, dot, backslash, equals, -- * Primitive type documents- string, int, integer, float, double, rational, bool,+ string, stringStrict, int, integer, float, double, rational, bool, -- * Position-based combinators column, nesting, width,@@ -112,23 +113,32 @@ Pretty(..), -- * Rendering- SimpleDoc(..), renderPretty, renderCompact, displayT,- displayIO, putDoc, hPutDoc+ SimpleDoc(..), renderPretty, renderCompact, renderOneLine,+ displayB, displayT, displayTStrict, displayIO, putDoc, hPutDoc ) where -import System.IO (Handle,hPutStr,hPutChar,stdout)+import Prelude ()+import Prelude.Compat hiding ((<$>)) -import qualified Data.Text.Lazy as T-import Data.Text.Lazy(Text)-import qualified Data.Text.Lazy.IO as T+import Data.String (IsString (..))+import System.IO (Handle, hPutChar, stdout)++import Data.Int (Int64)+import Data.List (intersperse)+import qualified Data.Text as TS+import Data.Text.Lazy (Text)+import qualified Data.Text.Lazy as T+import Data.Text.Lazy.Builder (Builder) import qualified Data.Text.Lazy.Builder as B-import Data.Text.Lazy.Builder(Builder)-import Data.Int(Int64)-import Data.Monoid(mempty,mappend)+import qualified Data.Text.Lazy.IO as T +#if !MIN_VERSION_base (4,9,0)+import Data.Monoid ((<>))+#endif+ infixr 5 </>,<//>,<$>,<$$>-infixr 6 <>,<+>+infixr 6 <+>,<++>,`beside` -----------------------------------------------------------@@ -171,13 +181,13 @@ -- > list xs = encloseSep lbracket rbracket comma xs -- > test = text "list" <+> (list (map int [10,200,3000])) ----- Which is layed out with a page width of 20 as:+-- Which is laid out with a page width of 20 as: -- -- @ -- list [10,200,3000] -- @ ----- But when the page width is 15, it is layed out as:+-- But when the page width is 15, it is laid out as: -- -- @ -- list [10@@ -185,11 +195,11 @@ -- ,3000] -- @ encloseSep :: Doc -> Doc -> Doc -> [Doc] -> Doc-encloseSep left right sep ds+encloseSep left right sp ds = case ds of [] -> left <> right [d] -> left <> d <> right- _ -> align (cat (zipWith (<>) (left : repeat sep) ds) <> right)+ _ -> align (cat (zipWith (<>) (left : repeat sp) ds) <> right) ----------------------------------------------------------- -- punctuate p [d1,d2,...,dn] => [d1 <> p,d2 <> p, ... ,dn]@@ -202,13 +212,13 @@ -- > someText = map text ["words","in","a","tuple"] -- > test = parens (align (cat (punctuate comma someText))) ----- This is layed out on a page width of 20 as:+-- This is laid out on a page width of 20 as: -- -- @ -- (words,in,a,tuple) -- @ ----- But when the page width is 15, it is layed out as:+-- But when the page width is 15, it is laid out as: -- -- @ -- (words,@@ -220,8 +230,8 @@ -- (If you want put the commas in front of their elements instead of -- at the end, you should use 'tupled' or, in general, 'encloseSep'.) punctuate :: Doc -> [Doc] -> [Doc]-punctuate p [] = []-punctuate p [d] = [d]+punctuate _ [] = []+punctuate _ [d] = [d] punctuate p (d:ds) = (d <> p) : punctuate p ds @@ -239,7 +249,7 @@ sep = group . vsep -- | The document @(fillSep xs)@ concatenates documents @xs@--- horizontally with @(\<+\>)@ as long as its fits the page, than+-- horizontally with @(\<+\>)@ as long as its fits the page, then -- inserts a @line@ and continues doing that for all documents in -- @xs@. --@@ -260,7 +270,7 @@ -- > -- > test = text "some" <+> vsep someText ----- This is layed out as:+-- This is laid out as: -- -- @ -- some text@@ -294,7 +304,7 @@ cat = group . vcat -- | The document @(fillCat xs)@ concatenates documents @xs@--- horizontally with @(\<\>)@ as long as its fits the page, than+-- horizontally with @(\<\>)@ as long as its fits the page, then -- inserts a @linebreak@ and continues doing that for all documents -- in @xs@. --@@ -314,22 +324,24 @@ vcat = fold (<$$>) fold :: (Doc -> Doc -> Doc) -> [Doc] -> Doc-fold f [] = empty+fold _ [] = empty fold f ds = foldr1 f ds --- | The document @(x \<\> y)@ concatenates document @x@ and document--- @y@. It is an associative operation having 'empty' as a left and--- right unit. (infixr 6)-(<>) :: Doc -> Doc -> Doc-x <> y = x `beside` y- -- | The document @(x \<+\> y)@ concatenates document @x@ and @y@ with--- a @space@ in between. (infixr 6)+-- a 'space' in between. (infixr 6) (<+>) :: Doc -> Doc -> Doc Empty <+> y = y x <+> Empty = x x <+> y = x <> space <> y +-- | The document @(x \<++\> y)@ concatenates document @x@ and @y@ with+-- a 'spacebreak' in between. (infixr 6)+(<++>) :: Doc -> Doc -> Doc+Empty <++> y = y+x <++> Empty = x+x <++> y = x <> spacebreak <> y++ -- | The document @(x \<\/\> y)@ concatenates document @x@ and @y@ -- with a 'softline' in between. This effectively puts @x@ and @y@ -- either next to each other (with a @space@ in between) or@@ -355,7 +367,7 @@ (<$>) = splitWithLine False -- | The document @(x \<$$\> y)@ concatenates document @x@ and @y@--- with a @linebreak@ in between. (infixr 5)+-- with a 'linebreak' in between. (infixr 5) (<$$>) :: Doc -> Doc -> Doc (<$$>) = splitWithLine True @@ -378,6 +390,11 @@ softbreak :: Doc softbreak = group linebreak +-- | The document @spacebreak@ behaves like 'space' when rendered normally+-- but like 'empty' when using 'renderCompact' or 'renderOneLine'.+spacebreak :: Doc+spacebreak = Spaces 1+ -- | Document @(squotes x)@ encloses document @x@ with single quotes -- \"'\". squotes :: Doc -> Doc@@ -496,41 +513,40 @@ -- characters. It is used instead of 'text' whenever the text -- contains newline characters. string :: Text -> Doc-string str = case T.uncons str of- Nothing -> empty- Just ('\n',str') -> line <> string str'- _ -> case (T.span (/='\n') str) of- (xs,ys) -> text xs <> string ys+string = mconcat . intersperse line . map text . T.lines +stringStrict :: TS.Text -> Doc+stringStrict = mconcat . intersperse line . map textStrict . TS.lines+ -- | The document @(bool b)@ shows the literal boolean @b@ using -- 'text'. bool :: Bool -> Doc-bool b = text' b+bool = text' -- | The document @(int i)@ shows the literal integer @i@ using -- 'text'. int :: Int -> Doc-int i = text' i+int = text' -- | The document @(integer i)@ shows the literal integer @i@ using -- 'text'. integer :: Integer -> Doc-integer i = text' i+integer = text' -- | The document @(float f)@ shows the literal float @f@ using -- 'text'. float :: Float -> Doc-float f = text' f+float = text' -- | The document @(double d)@ shows the literal double @d@ using -- 'text'. double :: Double -> Doc-double d = text' d+double = text' -- | The document @(rational r)@ shows the literal rational @r@ using -- 'text'. rational :: Rational -> Doc-rational r = text' r+rational = text' text' :: (Show a) => a -> Doc text' = text . T.pack . show@@ -557,40 +573,43 @@ instance Pretty Text where pretty = string +instance Pretty TS.Text where+ pretty = stringStrict+ instance Pretty () where pretty () = text' () instance Pretty Bool where- pretty b = bool b+ pretty = bool instance Pretty Char where- pretty c = char c+ pretty = char - prettyList s = string $ T.pack s+ prettyList = string . T.pack instance Pretty Int where- pretty i = int i+ pretty = int instance Pretty Integer where- pretty i = integer i+ pretty = integer instance Pretty Float where- pretty f = float f+ pretty = float instance Pretty Double where- pretty d = double d+ pretty = double --instance Pretty Rational where -- pretty r = rational r -instance (Pretty a,Pretty b) => Pretty (a,b) where+instance (Pretty a, Pretty b) => Pretty (a,b) where pretty (x,y) = tupled [pretty x, pretty y] -instance (Pretty a,Pretty b,Pretty c) => Pretty (a,b,c) where+instance (Pretty a, Pretty b, Pretty c) => Pretty (a,b,c) where pretty (x,y,z)= tupled [pretty x, pretty y, pretty z] instance Pretty a => Pretty (Maybe a) where- pretty Nothing = empty+ pretty Nothing = empty pretty (Just x) = pretty x @@ -599,7 +618,7 @@ ----------------------------------------------------------- -- | The document @(fillBreak i x)@ first renders document @x@. It--- than appends @space@s until the width is equal to @i@. If the+-- then appends @space@s until the width is equal to @i@. If the -- width of @x@ is already larger than @i@, the nesting level is -- increased by @i@ and a @line@ is appended. When we redefine -- @ptype@ in the previous example to use @fillBreak@, we get a@@ -618,13 +637,13 @@ -- @ fillBreak :: Int -> Doc -> Doc fillBreak f x = width x (\w ->- if (w > f)+ if w > f then nest f linebreak else spaced (f - w) ) --- | The document @(fill i x)@ renders document @x@. It than appends+-- | The document @(fill i x)@ renders document @x@. It then appends -- @space@s until the width is equal to @i@. If the width of @x@ is -- already larger, nothing is appended. This combinator is quite -- useful in practice to output a list of bindings. The following@@ -639,7 +658,7 @@ -- > -- > test = text "let" <+> align (vcat (map ptype types)) ----- Which is layed out as:+-- Which is laid out as: -- -- @ -- let empty :: Doc@@ -648,7 +667,7 @@ -- @ fill :: Int -> Doc -> Doc fill f d = width d (\w ->- if (w >= f)+ if w >= f then empty else spaced (f - w) )@@ -711,7 +730,7 @@ -- -- > test = text "hi" <+> (text "nice" $$ text "world") ----- which will be layed out as:+-- which will be laid out as: -- -- @ -- hi nice@@ -748,7 +767,23 @@ | Union Doc Doc -- invariant: first lines of first doc longer than the first lines of the second doc | Column (Int64 -> Doc) | Nesting (Int64 -> Doc)+ | Spaces !Int64 +instance IsString Doc where+ fromString = string . T.pack++-- | In particular, note that the document @(x '<>' y)@ concatenates+-- document @x@ and document @y@. It is an associative operation+-- having 'empty' as a left and right unit. (infixr 6)+#if MIN_VERSION_base (4,9,0)+instance Semigroup Doc where+ (<>) = beside++#endif+instance Monoid Doc where+ mempty = empty+ mappend = beside+ -- | The data type @SimpleDoc@ represents rendered documents and is -- used by the display functions. --@@ -768,6 +803,11 @@ empty :: Doc empty = Empty +-- | Determine if the document is empty or not.+isEmpty :: Doc -> Bool+isEmpty Empty = True+isEmpty _ = False+ -- | The document @(char c)@ contains the literal character @c@. The -- character shouldn't be a newline (@'\n'@), the function 'line' -- should be used for line breaks.@@ -784,9 +824,15 @@ | T.null s = Empty | otherwise = Text (T.length s) (B.fromLazyText s) +textStrict :: TS.Text -> Doc+textStrict s+ | TS.null s = Empty+ | otherwise = Text (fromIntegral $ TS.length s) (B.fromText s)+ -- | The @line@ document advances to the next line and indents to the -- current nesting level. Document @line@ behaves like @(text \"--- \")@ if the line break is undone by 'group'.+-- \")@ if the line break is undone by 'group' or if rendered with+-- 'renderOneLine'. line :: Doc line = Line False @@ -796,6 +842,11 @@ linebreak :: Doc linebreak = Line True +-- | The document @(x `beside` y)@ concatenates document @x@ and @y@.+-- It is an associative operation having 'empty' as a left and right+-- unit. (infixr 6)+--+-- It is equivalent to `<>`. beside :: Doc -> Doc -> Doc beside Empty r = r beside l Empty = l@@ -836,13 +887,13 @@ group x = Union (flatten x) x flatten :: Doc -> Doc-flatten (Cat x y) = Cat (flatten x) (flatten y)-flatten (Nest i x) = Nest i (flatten x)-flatten (Line break) = if break then Empty else Text 1 (B.singleton ' ')-flatten (Union x y) = flatten x-flatten (Column f) = Column (flatten . f)-flatten (Nesting f) = Nesting (flatten . f)-flatten other = other --Empty,Char,Text+flatten (Cat x y) = Cat (flatten x) (flatten y)+flatten (Nest i x) = Nest i (flatten x)+flatten (Line brk) = if brk then Empty else Text 1 (B.singleton ' ')+flatten (Union x _) = flatten x+flatten (Column f) = Column (flatten . f)+flatten (Nesting f) = Nesting (flatten . f)+flatten other = other --Empty,Char,Text ----------------------------------------------------------- -- Renderers@@ -865,8 +916,8 @@ -- is lower or higher, the ribbon width will be 0 or @width@ -- respectively. renderPretty :: Float -> Int -> Doc -> SimpleDoc-renderPretty rfrac w x- = best 0 0 (Cons 0 x Nil)+renderPretty rfrac w doc+ = best 0 0 (Cons 0 doc Nil) where -- r :: the ribbon width in characters r = max 0 (min w64 (round (fromIntegral w * rfrac)))@@ -876,7 +927,7 @@ -- best :: n = indentation of current line -- k = current column -- (ie. (k >= n) && (k - n == count of inserted characters)- best n k Nil = SEmpty+ best _ _ Nil = SEmpty best n k (Cons i d ds) = case d of Empty -> best n k ds@@ -889,23 +940,24 @@ (best n k $ Cons i y ds) Column f -> best n k (Cons i (f k) ds) Nesting f -> best n k (Cons i (f i) ds)+ Spaces l -> let k' = k+l in seq k' $ SText l (spaces l) (best n k' ds) --nicest :: r = ribbon width, w = page width, -- n = indentation of current line, k = current column -- x and y, the (simple) documents to chose from. -- precondition: first lines of x are longer than the first lines of y. nicest n k x y- | fits width x = x+ | fits wth x = x | otherwise = y where- width = min (w64 - k) (r - k + n)+ wth = min (w64 - k) (r - k + n) fits :: Int64 -> SimpleDoc -> Bool-fits w x | w < 0 = False-fits w SEmpty = True-fits w (SChar c x) = fits (w - 1) x-fits w (SText l s x) = fits (w - l) x-fits w (SLine i x) = True+fits w _ | w < 0 = False+fits _ SEmpty = True+fits w (SChar _ x) = fits (w - 1) x+fits w (SText l _ x) = fits (w - l) x+fits _ SLine{} = True ----------------------------------------------------------- -- renderCompact: renders documents without indentation@@ -918,10 +970,10 @@ -- characters than a pretty printed version and can be used for -- output that is read by other programs. renderCompact :: Doc -> SimpleDoc-renderCompact x- = scan 0 [x]+renderCompact dc+ = scan 0 [dc] where- scan k [] = SEmpty+ scan _ [] = SEmpty scan k (d:ds) = case d of Empty -> scan k ds@@ -929,11 +981,33 @@ Text l s -> let k' = k+l in seq k' (SText 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)+ Nest _ x -> scan k (x:ds)+ Union _ y -> scan k (y:ds) Column f -> scan k (f k:ds) Nesting f -> scan k (f 0:ds)+ Spaces _ -> scan k ds +-- | @(renderOneLine x)@ renders document @x@ without adding any+-- indentation or newlines.+renderOneLine :: Doc -> SimpleDoc+renderOneLine dc+ = scan 0 [dc]+ where+ scan _ [] = SEmpty+ scan k (d:ds)+ = case d of+ Empty -> scan k ds+ Char c -> let k' = k+1 in seq k' (SChar c (scan k' ds))+ Text l s -> let k' = k+l in seq k' (SText l s (scan k' ds))+ Line False -> let k' = k+1 in seq k' (SChar ' ' (scan k' ds))+ Line _ -> scan k ds+ Cat x y -> scan k (x:y:ds)+ Nest _ x -> scan k (x:ds)+ Union _ y -> scan k (y:ds)+ Column f -> scan k (f k:ds)+ Nesting f -> scan k (f 0:ds)+ Spaces _ -> scan k ds+ ----------------------------------------------------------- -- Displayers: displayS and displayIO -----------------------------------------------------------@@ -959,18 +1033,20 @@ displayT :: SimpleDoc -> Text displayT = B.toLazyText . displayB +displayTStrict :: SimpleDoc -> TS.Text+displayTStrict = T.toStrict . displayT+ -- | @(displayIO handle simpleDoc)@ writes @simpleDoc@ to the -- file handle @handle@. This function is used for example by -- 'hPutDoc': -- -- > hPutDoc handle doc = displayIO handle (renderPretty 0.4 100 doc) displayIO :: Handle -> SimpleDoc -> IO ()-displayIO handle simpleDoc- = display simpleDoc+displayIO handle = display where display SEmpty = return () display (SChar c x) = hPutChar handle c >> display x- display (SText l s x) = T.hPutStr handle (B.toLazyText s) >> display x+ display (SText _ s x) = T.hPutStr handle (B.toLazyText s) >> display x display (SLine i x) = T.hPutStr handle newLine >> display x where newLine = B.toLazyText $ '\n' `consB` indentation i@@ -981,7 +1057,11 @@ instance Show Doc where showsPrec d doc = showsPrec d (displayT $ renderPretty 0.4 80 doc)+ show doc = T.unpack (displayT $ renderPretty 0.4 80 doc) +instance Show SimpleDoc where+ show simpleDoc = T.unpack (displayT simpleDoc)+ -- | The action @(putDoc doc)@ pretty prints document @doc@ to the -- standard output, with a page width of 100 characters and a ribbon -- width of 40 characters.@@ -995,7 +1075,7 @@ -- hello world -- @ putDoc :: Doc -> IO ()-putDoc doc = hPutDoc stdout doc+putDoc = hPutDoc stdout -- | @(hPutDoc handle doc)@ pretty prints document @doc@ to the file -- handle @handle@ with a page width of 100 characters and a ribbon@@ -1019,7 +1099,7 @@ | otherwise = B.fromLazyText $ T.replicate n (T.singleton ' ') spaced :: Int -> Doc-spaced l = Text l' $ spaces l'+spaced l = Spaces l' where l' = fromIntegral l
Text/PrettyPrint/Leijen/Text/Monadic.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP, FlexibleInstances #-}+ ----------------------------------------------------------------------------- -- | -- Module : Text.PrettyPrint.Leijen.Text.Monadic@@ -19,25 +21,25 @@ Doc, -- putDoc, hPutDoc, -- * Basic combinators- empty, char, text, (<>), nest, line, linebreak, group, softline,- softbreak,+ empty, char, text, textStrict, beside, nest, line, linebreak, group, softline,+ softbreak, spacebreak, -- * Alignment --- -- The combinators in this section can not be described by Wadler's- -- original combinators. They align their output relative to the- -- current output position - in contrast to @nest@ which always- -- aligns to the current nesting level. This deprives these- -- combinators from being \`optimal\'. In practice however they- -- prove to be very useful. The combinators in this section should- -- be used with care, since they are more expensive than the other- -- combinators. For example, @align@ shouldn't be used to pretty- -- print all top-level declarations of a language, but using @hang@- -- for let expressions is fine.+ -- | The combinators in this section can not be described by Wadler's+ -- original combinators. They align their output relative to the+ -- current output position - in contrast to @nest@ which always+ -- aligns to the current nesting level. This deprives these+ -- combinators from being \`optimal\'. In practice however they+ -- prove to be very useful. The combinators in this section should+ -- be used with care, since they are more expensive than the other+ -- combinators. For example, @align@ shouldn't be used to pretty+ -- print all top-level declarations of a language, but using @hang@+ -- for let expressions is fine. align, hang, indent, encloseSep, list, tupled, semiBraces, -- * Operators- (<+>), (<$>), (</>), (<$$>), (<//>),+ (<+>), (<++>), (<$>), (</>), (<$$>), (<//>), -- * List combinators hsep, vsep, fillSep, sep, hcat, vcat, fillCat, cat, punctuate,@@ -53,7 +55,7 @@ squote, dquote, semi, colon, comma, space, dot, backslash, equals, -- * Primitive type documents- string, int, integer, float, double, rational, bool,+ string, stringStrict, int, integer, float, double, rational, bool, -- * Position-based combinators column, nesting, width,@@ -62,21 +64,28 @@ Pretty(..), prettyM, -- * Rendering- SimpleDoc(..), renderPretty, renderCompact, displayT,- displayIO, putDoc, hPutDoc+ SimpleDoc(..), renderPretty, renderCompact, renderOneLine,+ displayB, displayT, displayTStrict, displayIO, putDoc, hPutDoc ) where +import Prelude ()++import Prelude.Compat hiding ((<$>))++import Text.PrettyPrint.Leijen.Text (Doc, Pretty(..), SimpleDoc(..),+ displayB, displayIO, displayT,+ displayTStrict, hPutDoc, putDoc,+ renderCompact, renderOneLine,+ renderPretty) import qualified Text.PrettyPrint.Leijen.Text as PP-import Text.PrettyPrint.Leijen.Text( Doc, SimpleDoc(..), renderPretty, renderCompact- , displayT, displayIO, putDoc, hPutDoc, Pretty(..)) -import Control.Monad(liftM, liftM2, liftM3, liftM4)-import Data.Text.Lazy(Text)-import Data.Int(Int64)+import Control.Applicative (liftA2, liftA3)+import qualified Data.Text as TS+import Data.Text.Lazy (Text) infixr 5 </>,<//>,<$>,<$$>-infixr 6 <>,<+>+infixr 6 <+>,<++>,`beside` ----------------------------------------------------------- @@ -85,24 +94,24 @@ -- horizontally if that fits the page. Otherwise they are aligned -- vertically. All comma separators are put in front of the -- elements.-list :: (Monad m) => m [Doc] -> m Doc-list = liftM PP.list+list :: (Functor m) => m [Doc] -> m Doc+list = fmap PP.list -- | The document @(tupled xs)@ comma separates the documents @xs@ and -- encloses them in parenthesis. The documents are rendered -- horizontally if that fits the page. Otherwise they are aligned -- vertically. All comma separators are put in front of the -- elements.-tupled :: (Monad m) => m [Doc] -> m Doc-tupled = liftM PP.tupled+tupled :: (Functor m) => m [Doc] -> m Doc+tupled = fmap PP.tupled -- | The document @(semiBraces xs)@ separates the documents @xs@ with -- semi colons and encloses them in braces. The documents are -- rendered horizontally if that fits the page. Otherwise they are -- aligned vertically. All semi colons are put in front of the -- elements.-semiBraces :: (Monad m) => m [Doc] -> m Doc-semiBraces = liftM PP.semiBraces+semiBraces :: (Functor m) => m [Doc] -> m Doc+semiBraces = fmap PP.semiBraces -- | The document @(encloseSep l r sep xs)@ concatenates the documents -- @xs@ separated by @sep@ and encloses the resulting document by@@ -114,21 +123,21 @@ -- > list xs = encloseSep lbracket rbracket comma xs -- > test = text "list" <+> (list (map int [10,200,3000])) ----- Which is layed out with a page width of 20 as:+-- Which is laid out with a page width of 20 as: -- -- @ -- list [10,200,3000] -- @ ----- But when the page width is 15, it is layed out as:+-- But when the page width is 15, it is laid out as: -- -- @ -- list [10 -- ,200 -- ,3000] -- @-encloseSep :: (Monad m) => m Doc -> m Doc -> m Doc -> m [Doc] -> m Doc-encloseSep = liftM4 PP.encloseSep+encloseSep :: (Applicative m) => m Doc -> m Doc -> m Doc -> m [Doc] -> m Doc+encloseSep a b c d = liftA3 PP.encloseSep a b c <*> d -- | @(punctuate p xs)@ concatenates all documents in @xs@ with -- document @p@ except for the last document.@@ -136,13 +145,13 @@ -- > someText = map text ["words","in","a","tuple"] -- > test = parens (align (cat (punctuate comma someText))) ----- This is layed out on a page width of 20 as:+-- This is laid out on a page width of 20 as: -- -- @ -- (words,in,a,tuple) -- @ ----- But when the page width is 15, it is layed out as:+-- But when the page width is 15, it is laid out as: -- -- @ -- (words,@@ -153,30 +162,30 @@ -- -- (If you want put the commas in front of their elements instead of -- at the end, you should use 'tupled' or, in general, 'encloseSep'.)-punctuate :: (Monad m) => m Doc -> m [Doc] -> m [Doc]-punctuate = liftM2 PP.punctuate+punctuate :: (Applicative m) => m Doc -> m [Doc] -> m [Doc]+punctuate = liftA2 PP.punctuate -- | The document @(sep xs)@ concatenates all documents @xs@ either -- horizontally with @(\<+\>)@, if it fits the page, or vertically -- with @(\<$\>)@. -- -- > sep xs = group (vsep xs)-sep :: (Monad m) => m [Doc] -> m Doc-sep = liftM PP.sep+sep :: (Functor m) => m [Doc] -> m Doc+sep = fmap PP.sep -- | The document @(fillSep xs)@ concatenates documents @xs@--- horizontally with @(\<+\>)@ as long as its fits the page, than+-- horizontally with @(\<+\>)@ as long as its fits the page, then -- inserts a @line@ and continues doing that for all documents in -- @xs@. -- -- > fillSep xs = foldr (</>) empty xs-fillSep :: (Monad m) => m [Doc] -> m Doc-fillSep = liftM PP.fillSep+fillSep :: (Functor m) => m [Doc] -> m Doc+fillSep = fmap PP.fillSep -- | The document @(hsep xs)@ concatenates all documents @xs@ -- horizontally with @(\<+\>)@.-hsep :: (Monad m) => m [Doc] -> m Doc-hsep = liftM PP.hsep+hsep :: (Functor m) => m [Doc] -> m Doc+hsep = fmap PP.hsep -- | The document @(vsep xs)@ concatenates all documents @xs@ -- vertically with @(\<$\>)@. If a 'group' undoes the line breaks@@ -186,7 +195,7 @@ -- > -- > test = text "some" <+> vsep someText ----- This is layed out as:+-- This is laid out as: -- -- @ -- some text@@ -208,188 +217,198 @@ -- lay -- out -- @-vsep :: (Monad m) => m [Doc] -> m Doc-vsep = liftM PP.vsep+vsep :: (Functor m) => m [Doc] -> m Doc+vsep = fmap PP.vsep -- | The document @(cat xs)@ concatenates all documents @xs@ either -- horizontally with @(\<\>)@, if it fits the page, or vertically -- with @(\<$$\>)@. -- -- > cat xs = group (vcat xs)-cat :: (Monad m) => m [Doc] -> m Doc-cat = liftM PP.cat+cat :: (Functor m) => m [Doc] -> m Doc+cat = fmap PP.cat -- | The document @(fillCat xs)@ concatenates documents @xs@--- horizontally with @(\<\>)@ as long as its fits the page, than+-- horizontally with @(\<\>)@ as long as its fits the page, then -- inserts a @linebreak@ and continues doing that for all documents -- in @xs@. -- -- > fillCat xs = foldr (<//>) empty xs-fillCat :: (Monad m) => m [Doc] -> m Doc-fillCat = liftM PP.fillCat+fillCat :: (Functor m) => m [Doc] -> m Doc+fillCat = fmap PP.fillCat -- | The document @(hcat xs)@ concatenates all documents @xs@ -- horizontally with @(\<\>)@.-hcat :: (Monad m) => m [Doc] -> m Doc-hcat = liftM PP.hcat+hcat :: (Functor m) => m [Doc] -> m Doc+hcat = fmap PP.hcat -- | The document @(vcat xs)@ concatenates all documents @xs@ -- vertically with @(\<$$\>)@. If a 'group' undoes the line breaks -- inserted by @vcat@, all documents are directly concatenated.-vcat :: (Monad m) => m [Doc] -> m Doc-vcat = liftM PP.vcat+vcat :: (Functor m) => m [Doc] -> m Doc+vcat = fmap PP.vcat --- | The document @(x \<\> y)@ concatenates document @x@ and document--- @y@. It is an associative operation having 'empty' as a left and--- right unit. (infixr 6)-(<>) :: (Monad m) => m Doc -> m Doc -> m Doc-(<>) = liftM2 (PP.<>)+-- | The document @(x `beside` y)@ concatenates document @x@ and+-- document @y@. It is an associative operation having 'empty' as a+-- left and right unit. (infixr 6)+beside :: (Applicative m) => m Doc -> m Doc -> m Doc+beside = liftA2 (PP.beside) -- | The document @(x \<+\> y)@ concatenates document @x@ and @y@ with--- a @space@ in between. (infixr 6)-(<+>) :: (Monad m) => m Doc -> m Doc -> m Doc-(<+>) = liftM2 (PP.<+>)+-- a 'space' in between. (infixr 6)+(<+>) :: (Applicative m) => m Doc -> m Doc -> m Doc+(<+>) = liftA2 (PP.<+>) +-- | The document @(x \<++\> y)@ concatenates document @x@ and @y@ with+-- a 'spacebreak' in between. (infixr 6)+(<++>) :: (Applicative m) => m Doc -> m Doc -> m Doc+(<++>) = liftA2 (PP.<++>)+ -- | The document @(x \<\/\> y)@ concatenates document @x@ and @y@ -- with a 'softline' in between. This effectively puts @x@ and @y@ -- either next to each other (with a @space@ in between) or -- underneath each other. (infixr 5)-(</>) :: (Monad m) => m Doc -> m Doc -> m Doc-(</>) = liftM2 (PP.</>)+(</>) :: (Applicative m) => m Doc -> m Doc -> m Doc+(</>) = liftA2 (PP.</>) -- | The document @(x \<\/\/\> y)@ concatenates document @x@ and @y@ -- with a 'softbreak' in between. This effectively puts @x@ and @y@ -- either right next to each other or underneath each other. (infixr -- 5)-(<//>) :: (Monad m) => m Doc -> m Doc -> m Doc-(<//>) = liftM2 (PP.<//>)+(<//>) :: (Applicative m) => m Doc -> m Doc -> m Doc+(<//>) = liftA2 (PP.<//>) -- | The document @(x \<$\> y)@ concatenates document @x@ and @y@ with -- a 'line' in between. (infixr 5)-(<$>) :: (Monad m) => m Doc -> m Doc -> m Doc-(<$>) = liftM2 (PP.<$>)+(<$>) :: (Applicative m) => m Doc -> m Doc -> m Doc+(<$>) = liftA2 (PP.<$>) -- | The document @(x \<$$\> y)@ concatenates document @x@ and @y@--- with a @linebreak@ in between. (infixr 5)-(<$$>) :: (Monad m) => m Doc -> m Doc -> m Doc-(<$$>) = liftM2 (PP.<$$>)+-- with a 'linebreak' in between. (infixr 5)+(<$$>) :: (Applicative m) => m Doc -> m Doc -> m Doc+(<$$>) = liftA2 (PP.<$$>) -- | The document @softline@ behaves like 'space' if the resulting -- output fits the page, otherwise it behaves like 'line'.-softline :: (Monad m) => m Doc-softline = return PP.softline+softline :: (Applicative m) => m Doc+softline = pure PP.softline -- | The document @softbreak@ behaves like 'empty' if the resulting -- output fits the page, otherwise it behaves like 'line'.-softbreak :: (Monad m) => m Doc-softbreak = return PP.softbreak+softbreak :: (Applicative m) => m Doc+softbreak = pure PP.softbreak +-- | The document @spacebreak@ behaves like 'space' when rendered normally+-- but like 'empty' when using 'renderCompact' or 'renderOneLine'.+spacebreak :: (Applicative m) => m Doc+spacebreak = pure PP.spacebreak+ -- | Document @(squotes x)@ encloses document @x@ with single quotes -- \"'\".-squotes :: (Monad m) => m Doc -> m Doc-squotes = liftM PP.squotes+squotes :: (Functor m) => m Doc -> m Doc+squotes = fmap PP.squotes -- | Document @(dquotes x)@ encloses document @x@ with double quotes -- '\"'.-dquotes :: (Monad m) => m Doc -> m Doc-dquotes = liftM PP.dquotes+dquotes :: (Functor m) => m Doc -> m Doc+dquotes = fmap PP.dquotes -- | Document @(braces x)@ encloses document @x@ in braces, \"{\" and -- \"}\".-braces :: (Monad m) => m Doc -> m Doc-braces = liftM PP.braces+braces :: (Functor m) => m Doc -> m Doc+braces = fmap PP.braces -- | Document @(parens x)@ encloses document @x@ in parenthesis, \"(\" -- and \")\".-parens :: (Monad m) => m Doc -> m Doc-parens = liftM PP.parens+parens :: (Functor m) => m Doc -> m Doc+parens = fmap PP.parens -- | Document @(angles x)@ encloses document @x@ in angles, \"\<\" and -- \"\>\".-angles :: (Monad m) => m Doc -> m Doc-angles = liftM PP.angles+angles :: (Functor m) => m Doc -> m Doc+angles = fmap PP.angles -- | Document @(brackets x)@ encloses document @x@ in square brackets, -- \"[\" and \"]\".-brackets :: (Monad m) => m Doc -> m Doc-brackets = liftM PP.brackets+brackets :: (Functor m) => m Doc -> m Doc+brackets = fmap PP.brackets -- | The document @(enclose l r x)@ encloses document @x@ between--- documents @l@ and @r@ using @(\<\>)@.+-- documents @l@ and @r@ using @'beside'@. ----- > enclose l r x = l <> x <> r-enclose :: (Monad m) => m Doc -> m Doc -> m Doc -> m Doc-enclose = liftM3 PP.enclose+-- > enclose l r x = l `beside` x `beside` r+enclose :: (Applicative m) => m Doc -> m Doc -> m Doc -> m Doc+enclose = liftA3 PP.enclose -- | The document @lparen@ contains a left parenthesis, \"(\".-lparen :: (Monad m) => m Doc-lparen = return PP.lparen+lparen :: (Applicative m) => m Doc+lparen = pure PP.lparen -- | The document @rparen@ contains a right parenthesis, \")\".-rparen :: (Monad m) => m Doc-rparen = return PP.rparen+rparen :: (Applicative m) => m Doc+rparen = pure PP.rparen -- | The document @langle@ contains a left angle, \"\<\".-langle :: (Monad m) => m Doc-langle = return PP.langle+langle :: (Applicative m) => m Doc+langle = pure PP.langle -- | The document @rangle@ contains a right angle, \">\".-rangle :: (Monad m) => m Doc-rangle = return PP.rangle+rangle :: (Applicative m) => m Doc+rangle = pure PP.rangle -- | The document @lbrace@ contains a left brace, \"{\".-lbrace :: (Monad m) => m Doc-lbrace = return PP.lbrace+lbrace :: (Applicative m) => m Doc+lbrace = pure PP.lbrace -- | The document @rbrace@ contains a right brace, \"}\".-rbrace :: (Monad m) => m Doc-rbrace = return PP.rbrace+rbrace :: (Applicative m) => m Doc+rbrace = pure PP.rbrace -- | The document @lbracket@ contains a left square bracket, \"[\".-lbracket :: (Monad m) => m Doc-lbracket = return PP.lbracket+lbracket :: (Applicative m) => m Doc+lbracket = pure PP.lbracket -- | The document @rbracket@ contains a right square bracket, \"]\".-rbracket :: (Monad m) => m Doc-rbracket = return PP.rbracket+rbracket :: (Applicative m) => m Doc+rbracket = pure PP.rbracket -- | The document @squote@ contains a single quote, \"'\".-squote :: (Monad m) => m Doc-squote = return PP.squote+squote :: (Applicative m) => m Doc+squote = pure PP.squote -- | The document @dquote@ contains a double quote, '\"'.-dquote :: (Monad m) => m Doc-dquote = return PP.dquote+dquote :: (Applicative m) => m Doc+dquote = pure PP.dquote -- | The document @semi@ contains a semi colon, \";\".-semi :: (Monad m) => m Doc-semi = return PP.semi+semi :: (Applicative m) => m Doc+semi = pure PP.semi -- | The document @colon@ contains a colon, \":\".-colon :: (Monad m) => m Doc-colon = return PP.colon+colon :: (Applicative m) => m Doc+colon = pure PP.colon -- | The document @comma@ contains a comma, \",\".-comma :: (Monad m) => m Doc-comma = return PP.comma+comma :: (Applicative m) => m Doc+comma = pure PP.comma -- | The document @space@ contains a single space, \" \". ----- > x <+> y = x <> space <> y-space :: (Monad m) => m Doc-space = return PP.space+-- > x <+> y = x `beside` space `beside` y+space :: (Applicative m) => m Doc+space = pure PP.space -- | The document @dot@ contains a single dot, \".\".-dot :: (Monad m) => m Doc-dot = return PP.dot+dot :: (Applicative m) => m Doc+dot = pure PP.dot -- | The document @backslash@ contains a back slash, \"\\\".-backslash :: (Monad m) => m Doc-backslash = return PP.backslash+backslash :: (Applicative m) => m Doc+backslash = pure PP.backslash -- | The document @equals@ contains an equal sign, \"=\".-equals :: (Monad m) => m Doc-equals = return PP.equals+equals :: (Applicative m) => m Doc+equals = pure PP.equals ----------------------------------------------------------- -- Combinators for prelude types@@ -399,47 +418,50 @@ -- using @line@ for newline characters and @char@ for all other -- characters. It is used instead of 'text' whenever the text -- contains newline characters.-string :: (Monad m) => Text -> m Doc-string = return . PP.string+string :: (Applicative m) => Text -> m Doc+string = pure . PP.string +stringStrict :: Monad m => TS.Text -> m Doc+stringStrict = return . PP.stringStrict+ -- | The document @(bool b)@ shows the literal boolean @b@ using -- 'text'.-bool :: (Monad m) => Bool -> m Doc-bool = return . PP.bool+bool :: (Applicative m) => Bool -> m Doc+bool = pure . PP.bool -- | The document @(int i)@ shows the literal integer @i@ using -- 'text'.-int :: (Monad m) => Int -> m Doc-int = return . PP.int+int :: (Applicative m) => Int -> m Doc+int = pure . PP.int -- | The document @(integer i)@ shows the literal integer @i@ using -- 'text'.-integer :: (Monad m) => Integer -> m Doc-integer = return . PP.integer+integer :: (Applicative m) => Integer -> m Doc+integer = pure . PP.integer -- | The document @(float f)@ shows the literal float @f@ using -- 'text'.-float :: (Monad m) => Float -> m Doc-float = return . PP.float+float :: (Applicative m) => Float -> m Doc+float = pure . PP.float -- | The document @(double d)@ shows the literal double @d@ using -- 'text'.-double :: (Monad m) => Double -> m Doc-double = return . PP.double+double :: (Applicative m) => Double -> m Doc+double = pure . PP.double -- | The document @(rational r)@ shows the literal rational @r@ using -- 'text'.-rational :: (Monad m) => Rational -> m Doc-rational = return . PP.rational+rational :: (Applicative m) => Rational -> m Doc+rational = pure . PP.rational -- | A monadic version of 'pretty'; this is to allow you to use the -- 'Pretty' class without having to create extra instances. -- Alternatively, you may wish to make a variant of 'Pretty' using -- the actual 'Monad' to be used.-prettyM :: (Pretty a, Monad m) => a -> m Doc-prettyM = return . pretty+prettyM :: (Pretty a, Applicative m) => a -> m Doc+prettyM = pure . pretty --- | The document @(fill i x)@ renders document @x@. It than appends+-- | The document @(fill i x)@ renders document @x@. It then appends -- @space@s until the width is equal to @i@. If the width of @x@ is -- already larger, nothing is appended. This combinator is quite -- useful in practice to output a list of bindings. The following@@ -454,22 +476,22 @@ -- > -- > test = text "let" <+> align (vcat (map ptype types)) ----- Which is layed out as:+-- Which is laid out as: -- -- @ -- let empty :: Doc -- nest :: Int -> Doc -> Doc -- linebreak :: Doc -- @-fill :: (Monad m) => Int -> m Doc -> m Doc-fill = liftM . PP.fill+fill :: (Functor m) => Int -> m Doc -> m Doc+fill = fmap . PP.fill -width :: (Monad m) => m Doc -> m (Int -> Doc) -> m Doc-width = liftM2 PP.width+width :: (Applicative m) => m Doc -> m (Int -> Doc) -> m Doc+width = liftA2 PP.width -- | The document @(fillBreak i x)@ first renders document @x@. It--- than appends @space@s until the width is equal to @i@. If the+-- then appends @space@s until the width is equal to @i@. If the -- width of @x@ is already larger than @i@, the nesting level is -- increased by @i@ and a @line@ is appended. When we redefine -- @ptype@ in the previous example to use @fillBreak@, we get a@@ -486,8 +508,8 @@ -- linebreak -- :: Doc -- @-fillBreak :: (Monad m) => Int -> m Doc -> m Doc-fillBreak = liftM . PP.fillBreak+fillBreak :: (Functor m) => Int -> m Doc -> m Doc+fillBreak = fmap . PP.fillBreak -- | The document @(indent i x)@ indents document @x@ with @i@ spaces. --@@ -502,8 +524,8 @@ -- indents these -- words ! -- @-indent :: (Monad m) => Int -> m Doc -> m Doc-indent = liftM . PP.indent+indent :: (Functor m) => Int -> m Doc -> m Doc+indent = fmap . PP.indent -- | The hang combinator implements hanging indentation. The document -- @(hang i x)@ renders document @x@ with a nesting level set to the@@ -524,8 +546,8 @@ -- The @hang@ combinator is implemented as: -- -- > hang i x = align (nest i x)-hang :: (Monad m) => Int -> m Doc -> m Doc-hang = liftM . PP.hang+hang :: (Functor m) => Int -> m Doc -> m Doc+hang = fmap . PP.hang -- | The document @(align x)@ renders document @x@ with the nesting -- level set to the current column. It is used for example to@@ -538,45 +560,49 @@ -- -- > test = text "hi" <+> (text "nice" $$ text "world") ----- which will be layed out as:+-- which will be laid out as: -- -- @ -- hi nice -- world -- @-align :: (Monad m) => m Doc -> m Doc-align = liftM PP.align+align :: (Functor m) => m Doc -> m Doc+align = fmap PP.align -- | The empty document is, indeed, empty. Although @empty@ has no -- content, it does have a \'height\' of 1 and behaves exactly like -- @(text \"\")@ (and is therefore not a unit of @\<$\>@).-empty :: (Monad m) => m Doc-empty = return PP.empty+empty :: (Applicative m) => m Doc+empty = pure PP.empty -- | The document @(char c)@ contains the literal character @c@. The -- character shouldn't be a newline (@'\n'@), the function 'line' -- should be used for line breaks.-char :: (Monad m) => Char -> m Doc-char = return . PP.char+char :: (Applicative m) => Char -> m Doc+char = pure . PP.char -- | The document @(text s)@ contains the literal string @s@. The -- string shouldn't contain any newline (@'\n'@) characters. If the -- string contains newline characters, the function 'string' should -- be used.-text :: (Monad m) => Text -> m Doc-text = return . PP.text+text :: (Applicative m) => Text -> m Doc+text = pure . PP.text +textStrict :: Monad m => TS.Text -> m Doc+textStrict = return . PP.textStrict+ -- | The @line@ document advances to the next line and indents to the -- current nesting level. Document @line@ behaves like @(text \"--- \")@ if the line break is undone by 'group'.-line :: (Monad m) => m Doc-line = return PP.line+-- \")@ if the line break is undone by 'group' or if rendered with+-- 'renderOneLine'.+line :: (Applicative m) => m Doc+line = pure PP.line -- | The @linebreak@ document advances to the next line and indents to -- the current nesting level. Document @linebreak@ behaves like -- 'empty' if the line break is undone by 'group'.-linebreak :: (Monad m) => m Doc-linebreak = return PP.linebreak+linebreak :: (Applicative m) => m Doc+linebreak = pure PP.linebreak -- | The document @(nest i x)@ renders document @x@ with the current -- indentation level increased by @i@ (See also 'hang', 'align' and@@ -591,23 +617,22 @@ -- world -- ! -- @-nest :: (Monad m) => Int -> m Doc -> m Doc-nest = liftM . PP.nest+nest :: (Functor m) => Int -> m Doc -> m Doc+nest = fmap . PP.nest -- | Specifies how to create the document based upon which column it is in.-column :: (Monad m) => m (Int -> Doc) -> m Doc-column = liftM PP.column+column :: (Functor m) => m (Int -> Doc) -> m Doc+column = fmap PP.column -- | Specifies how to nest the document based upon which column it is -- being nested in.-nesting :: (Monad m) => m (Int -> Doc) -> m Doc-nesting = liftM PP.nesting+nesting :: (Functor m) => m (Int -> Doc) -> m Doc+nesting = fmap PP.nesting -- | The @group@ combinator is used to specify alternative -- layouts. The document @(group x)@ undoes all line breaks in -- document @x@. The resulting line is added to the current line if -- that fits the page. Otherwise, the document @x@ is rendered -- without any changes.-group :: (Monad m) => m Doc -> m Doc-group = liftM PP.group-+group :: (Functor m) => m Doc -> m Doc+group = fmap PP.group
wl-pprint-text.cabal view
@@ -1,5 +1,6 @@+Cabal-version: >=1.10 Name: wl-pprint-text-Version: 1.0.0.0+Version: 1.2.0.2 Synopsis: A Wadler/Leijen Pretty Printer for Text values Description: A clone of wl-pprint for use with the text library. License: BSD3@@ -9,14 +10,33 @@ Copyright: 2007 Daan Leijen, 2010 Ivan Lazar Miljenovic Category: Text Build-type: Simple-Cabal-version: >=1.6 +Tested-With:+ GHC == 7.4.2+ GHC == 7.6.3+ GHC == 7.8.4+ GHC == 7.10.3+ GHC == 8.0.2+ GHC == 8.2.2+ GHC == 8.4.4+ GHC == 8.6.5+ GHC == 8.8.4+ GHC == 8.10.7+ GHC == 9.0.1+ GHC == 9.2.1++Extra-Source-Files: Changelog.md+ README.md+ Source-Repository head- type: darcs- location: http://code.haskell.org/~ivanm/wl-pprint-text+ type: git+ location: https://github.com/ivan-m/wl-pprint-text.git Library Exposed-modules: Text.PrettyPrint.Leijen.Text, Text.PrettyPrint.Leijen.Text.Monadic- Build-depends: base < 5,- text >= 0.11.0.0 && < 0.12.0.0+ Build-depends: base >= 4.5.0.0 && < 5,+ base-compat >= 0.10 && < 0.13,+ text >= 0.11.0.0 && < 2.1+ Default-language: Haskell98+ GHC-Options: -Wall