prettyprinter-combinators-0.1.1.1: Some useful combinators for the prettyprinter package
Copyright(c) Sergey Vinokurov 2018
LicenseApache-2.0 (see LICENSE)
Maintainerserg.foo@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Prettyprinter.Combinators

Description

 
Synopsis

Documentation

class Pretty a where #

Overloaded conversion to Doc.

Laws:

  1. output should be pretty. :-)

Minimal complete definition

pretty

Methods

pretty :: a -> Doc ann #

>>> pretty 1 <+> pretty "hello" <+> pretty 1.234
1 hello 1.234

prettyList :: [a] -> Doc ann #

prettyList is only used to define the instance Pretty a => Pretty [a]. In normal circumstances only the pretty function is used.

>>> prettyList [1, 23, 456]
[1, 23, 456]

Instances

Instances details
Pretty Void

Finding a good example for printing something that does not exist is hard, so here is an example of printing a list full of nothing.

>>> pretty ([] :: [Void])
[]
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Void -> Doc ann #

prettyList :: [Void] -> Doc ann #

Pretty Int16 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Int16 -> Doc ann #

prettyList :: [Int16] -> Doc ann #

Pretty Int32 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Int32 -> Doc ann #

prettyList :: [Int32] -> Doc ann #

Pretty Int64 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Int64 -> Doc ann #

prettyList :: [Int64] -> Doc ann #

Pretty Int8 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Int8 -> Doc ann #

prettyList :: [Int8] -> Doc ann #

Pretty Word16 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Word16 -> Doc ann #

prettyList :: [Word16] -> Doc ann #

Pretty Word32 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Word32 -> Doc ann #

prettyList :: [Word32] -> Doc ann #

Pretty Word64 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Word64 -> Doc ann #

prettyList :: [Word64] -> Doc ann #

Pretty Word8 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Word8 -> Doc ann #

prettyList :: [Word8] -> Doc ann #

Pretty Text

Automatically converts all newlines to line.

>>> pretty ("hello\nworld" :: Text)
hello
world

Note that line can be undone by group:

>>> group (pretty ("hello\nworld" :: Text))
hello world

Manually use hardline if you definitely want newlines.

Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Text -> Doc ann #

prettyList :: [Text] -> Doc ann #

Pretty Text

(lazy Doc instance, identical to the strict version)

Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Text -> Doc ann #

prettyList :: [Text] -> Doc ann #

Pretty Integer
>>> pretty (2^123 :: Integer)
10633823966279326983230456482242756608
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Integer -> Doc ann #

prettyList :: [Integer] -> Doc ann #

Pretty Natural 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Natural -> Doc ann #

prettyList :: [Natural] -> Doc ann #

Pretty ()
>>> pretty ()
()

The argument is not used:

>>> pretty (error "Strict?" :: ())
()
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: () -> Doc ann #

prettyList :: [()] -> Doc ann #

Pretty Bool
>>> pretty True
True
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Bool -> Doc ann #

prettyList :: [Bool] -> Doc ann #

Pretty Char

Instead of (pretty 'n'), consider using line as a more readable alternative.

>>> pretty 'f' <> pretty 'o' <> pretty 'o'
foo
>>> pretty ("string" :: String)
string
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Char -> Doc ann #

prettyList :: [Char] -> Doc ann #

Pretty Double
>>> pretty (exp 1 :: Double)
2.71828182845904...
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Double -> Doc ann #

prettyList :: [Double] -> Doc ann #

Pretty Float
>>> pretty (pi :: Float)
3.1415927
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Float -> Doc ann #

prettyList :: [Float] -> Doc ann #

Pretty Int
>>> pretty (123 :: Int)
123
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Int -> Doc ann #

prettyList :: [Int] -> Doc ann #

Pretty Word 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Word -> Doc ann #

prettyList :: [Word] -> Doc ann #

Pretty a => Pretty (Identity a)
>>> pretty (Identity 1)
1
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Identity a -> Doc ann #

prettyList :: [Identity a] -> Doc ann #

Pretty a => Pretty (NonEmpty a) 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: NonEmpty a -> Doc ann #

prettyList :: [NonEmpty a] -> Doc ann #

Pretty a => Pretty (Maybe a)

Ignore Nothings, print Just contents.

>>> pretty (Just True)
True
>>> braces (pretty (Nothing :: Maybe Bool))
{}
>>> pretty [Just 1, Nothing, Just 3, Nothing]
[1, 3]
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Maybe a -> Doc ann #

prettyList :: [Maybe a] -> Doc ann #

Pretty a => Pretty [a]
>>> pretty [1,2,3]
[1, 2, 3]
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: [a] -> Doc ann #

prettyList :: [[a]] -> Doc ann #

(Pretty k, Pretty v) => Pretty (MapEntry k v) Source # 
Instance details

Defined in Prettyprinter.Combinators

Methods

pretty :: MapEntry k v -> Doc ann #

prettyList :: [MapEntry k v] -> Doc ann #

(Pretty a1, Pretty a2) => Pretty (a1, a2)
>>> pretty (123, "hello")
(123, hello)
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: (a1, a2) -> Doc ann #

prettyList :: [(a1, a2)] -> Doc ann #

Pretty a => Pretty (Const a b) 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Const a b -> Doc ann #

prettyList :: [Const a b] -> Doc ann #

(Pretty a1, Pretty a2, Pretty a3) => Pretty (a1, a2, a3)
>>> pretty (123, "hello", False)
(123, hello, False)
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: (a1, a2, a3) -> Doc ann #

prettyList :: [(a1, a2, a3)] -> Doc ann #

data Doc ann #

The abstract data type Doc ann represents pretty documents that have been annotated with data of type ann.

More specifically, a value of type Doc represents a non-empty set of possible layouts of a document. The layout functions select one of these possibilities, taking into account things like the width of the output document.

The annotation is an arbitrary piece of data associated with (part of) a document. Annotations may be used by the rendering backends in order to display output differently, such as

  • color information (e.g. when rendering to the terminal)
  • mouseover text (e.g. when rendering to rich HTML)
  • whether to show something or not (to allow simple or detailed versions)

The simplest way to display a Doc is via the Show class.

>>> putStrLn (show (vsep ["hello", "world"]))
hello
world

Instances

Instances details
Functor Doc

Alter the document’s annotations.

This instance makes Doc more flexible (because it can be used in Functor-polymorphic values), but fmap is much less readable compared to using reAnnotate in code that only works for Doc anyway. Consider using the latter when the type does not matter.

Instance details

Defined in Prettyprinter.Internal

Methods

fmap :: (a -> b) -> Doc a -> Doc b #

(<$) :: a -> Doc b -> Doc a #

IsString (Doc ann)
>>> pretty ("hello\nworld")
hello
world

This instance uses the Pretty Doc instance, and uses the same newline to line conversion.

Instance details

Defined in Prettyprinter.Internal

Methods

fromString :: String -> Doc ann #

Monoid (Doc ann)
mempty = emptyDoc
mconcat = hcat
>>> mappend "hello" "world" :: Doc ann
helloworld
Instance details

Defined in Prettyprinter.Internal

Methods

mempty :: Doc ann #

mappend :: Doc ann -> Doc ann -> Doc ann #

mconcat :: [Doc ann] -> Doc ann #

Semigroup (Doc ann)
x <> y = hcat [x, y]
>>> "hello" <> "world" :: Doc ann
helloworld
Instance details

Defined in Prettyprinter.Internal

Methods

(<>) :: Doc ann -> Doc ann -> Doc ann #

sconcat :: NonEmpty (Doc ann) -> Doc ann #

stimes :: Integral b => b -> Doc ann -> Doc ann #

Generic (Doc ann) 
Instance details

Defined in Prettyprinter.Internal

Associated Types

type Rep (Doc ann) :: Type -> Type #

Methods

from :: Doc ann -> Rep (Doc ann) x #

to :: Rep (Doc ann) x -> Doc ann #

Show (Doc ann)

(show doc) prettyprints document doc with defaultLayoutOptions, ignoring all annotations.

Instance details

Defined in Prettyprinter.Internal

Methods

showsPrec :: Int -> Doc ann -> ShowS #

show :: Doc ann -> String #

showList :: [Doc ann] -> ShowS #

PPGenericOverride (Doc Void) Source # 
Instance details

Defined in Prettyprinter.Generics

type Rep (Doc ann) 
Instance details

Defined in Prettyprinter.Internal

type Rep (Doc ann) = D1 ('MetaData "Doc" "Prettyprinter.Internal" "prettyprinter-1.7.1-Fnq1Vt2JMTY81kvR0W9kdP" 'False) (((C1 ('MetaCons "Fail" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Empty" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Char" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Char)))) :+: (C1 ('MetaCons "Text" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: (C1 ('MetaCons "Line" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "FlatAlt" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann)))))) :+: ((C1 ('MetaCons "Cat" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann))) :+: (C1 ('MetaCons "Nest" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann))) :+: C1 ('MetaCons "Union" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann))))) :+: ((C1 ('MetaCons "Column" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Int -> Doc ann))) :+: C1 ('MetaCons "WithPageWidth" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PageWidth -> Doc ann)))) :+: (C1 ('MetaCons "Nesting" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Int -> Doc ann))) :+: C1 ('MetaCons "Annotated" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ann) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann)))))))

putDocLn :: Doc ann -> IO () Source #

render :: Doc ann -> Text Source #

viaShow :: Show a => a -> Doc ann #

Convenience function to convert a Showable value to a Doc. If the String does not contain newlines, consider using the more performant unsafeViaShow.

data MapEntry k v Source #

Constructors

k :-> v infixr 0 

Instances

Instances details
Foldable (MapEntry k) Source # 
Instance details

Defined in Prettyprinter.Combinators

Methods

fold :: Monoid m => MapEntry k m -> m #

foldMap :: Monoid m => (a -> m) -> MapEntry k a -> m #

foldMap' :: Monoid m => (a -> m) -> MapEntry k a -> m #

foldr :: (a -> b -> b) -> b -> MapEntry k a -> b #

foldr' :: (a -> b -> b) -> b -> MapEntry k a -> b #

foldl :: (b -> a -> b) -> b -> MapEntry k a -> b #

foldl' :: (b -> a -> b) -> b -> MapEntry k a -> b #

foldr1 :: (a -> a -> a) -> MapEntry k a -> a #

foldl1 :: (a -> a -> a) -> MapEntry k a -> a #

toList :: MapEntry k a -> [a] #

null :: MapEntry k a -> Bool #

length :: MapEntry k a -> Int #

elem :: Eq a => a -> MapEntry k a -> Bool #

maximum :: Ord a => MapEntry k a -> a #

minimum :: Ord a => MapEntry k a -> a #

sum :: Num a => MapEntry k a -> a #

product :: Num a => MapEntry k a -> a #

Traversable (MapEntry k) Source # 
Instance details

Defined in Prettyprinter.Combinators

Methods

traverse :: Applicative f => (a -> f b) -> MapEntry k a -> f (MapEntry k b) #

sequenceA :: Applicative f => MapEntry k (f a) -> f (MapEntry k a) #

mapM :: Monad m => (a -> m b) -> MapEntry k a -> m (MapEntry k b) #

sequence :: Monad m => MapEntry k (m a) -> m (MapEntry k a) #

Functor (MapEntry k) Source # 
Instance details

Defined in Prettyprinter.Combinators

Methods

fmap :: (a -> b) -> MapEntry k a -> MapEntry k b #

(<$) :: a -> MapEntry k b -> MapEntry k a #

(Show k, Show v) => Show (MapEntry k v) Source # 
Instance details

Defined in Prettyprinter.Combinators

Methods

showsPrec :: Int -> MapEntry k v -> ShowS #

show :: MapEntry k v -> String #

showList :: [MapEntry k v] -> ShowS #

(Eq k, Eq v) => Eq (MapEntry k v) Source # 
Instance details

Defined in Prettyprinter.Combinators

Methods

(==) :: MapEntry k v -> MapEntry k v -> Bool #

(/=) :: MapEntry k v -> MapEntry k v -> Bool #

(Ord k, Ord v) => Ord (MapEntry k v) Source # 
Instance details

Defined in Prettyprinter.Combinators

Methods

compare :: MapEntry k v -> MapEntry k v -> Ordering #

(<) :: MapEntry k v -> MapEntry k v -> Bool #

(<=) :: MapEntry k v -> MapEntry k v -> Bool #

(>) :: MapEntry k v -> MapEntry k v -> Bool #

(>=) :: MapEntry k v -> MapEntry k v -> Bool #

max :: MapEntry k v -> MapEntry k v -> MapEntry k v #

min :: MapEntry k v -> MapEntry k v -> MapEntry k v #

(Pretty k, Pretty v) => Pretty (MapEntry k v) Source # 
Instance details

Defined in Prettyprinter.Combinators

Methods

pretty :: MapEntry k v -> Doc ann #

prettyList :: [MapEntry k v] -> Doc ann #

(-->) :: Pretty v => Text -> v -> MapEntry Text (Doc ann) infixr 0 Source #

Helper to make constructing MapEntry pairs easier by calling pretty on value.

ppMapEntryWith :: (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann Source #

ppMapEntryWithSep :: Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann Source #

ppList :: Pretty a => [a] -> Doc ann Source #

(##) :: Doc ann -> Doc ann -> Doc ann infixr 6 Source #

ppDictHeader :: Doc ann -> [MapEntry Text (Doc ann)] -> Doc ann Source #

ppTuple :: Pretty a => [a] -> Doc ann Source #

ppTupleWith :: (a -> Doc ann) -> [a] -> Doc ann Source #

ppListWith :: (a -> Doc ann) -> [a] -> Doc ann Source #

ppFoldableHeader :: (Pretty a, Foldable f) => Doc ann -> f a -> Doc ann Source #

ppFoldableHeaderWith :: Foldable f => (a -> Doc ann) -> Doc ann -> f a -> Doc ann Source #

ppNE :: Pretty a => NonEmpty a -> Doc ann Source #

ppNEWith :: (a -> Doc ann) -> NonEmpty a -> Doc ann Source #

ppMap :: (Pretty a, Pretty b) => Map a b -> Doc ann Source #

ppMapWith :: (k -> Doc ann) -> (v -> Doc ann) -> Map k v -> Doc ann Source #

ppSet :: Pretty a => Set a -> Doc ann Source #

ppSetWith :: (a -> Doc ann) -> Set a -> Doc ann Source #

ppBimap :: (Pretty k, Pretty v) => Bimap k v -> Doc ann Source #

ppBimapWith :: (k -> Doc ann) -> (v -> Doc ann) -> Bimap k v -> Doc ann Source #

ppIntSetWith :: (Int -> Doc ann) -> IntSet -> Doc ann Source #

ppIntMap :: Pretty a => IntMap a -> Doc ann Source #

ppIntMapWith :: (Int -> Doc ann) -> (a -> Doc ann) -> IntMap a -> Doc ann Source #

ppHashSet :: Pretty a => HashSet a -> Doc ann Source #

ppHashSetWith :: (a -> Doc ann) -> HashSet a -> Doc ann Source #

ppHashMap :: (Pretty k, Pretty v) => HashMap k v -> Doc ann Source #

ppHashMapWith :: (k -> Doc ann) -> (v -> Doc ann) -> HashMap k v -> Doc ann Source #

ppVector :: (Vector v a, Pretty a) => v a -> Doc ann Source #

ppVectorWith :: Vector v a => (a -> Doc ann) -> v a -> Doc ann Source #

ppDList :: Pretty a => DList a -> Doc ann Source #

ppDListWith :: (a -> Doc ann) -> DList a -> Doc ann Source #

ppListWithDelim :: forall f ann. Foldable f => Doc ann -> Doc ann -> f (Doc ann) -> Doc ann Source #

ppAssocList :: (Pretty k, Pretty v) => [(k, v)] -> Doc ann Source #

ppAssocListWith :: (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann Source #

ppAssocListWithSep :: Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann Source #

ppCallStackGHC :: CallStack -> Doc ann Source #

Pretty-print a CallStack just as GHC would.