Copyright | (c) Sergey Vinokurov 2018 |
---|---|
License | Apache-2.0 (see LICENSE) |
Maintainer | serg.foo@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- class Pretty a where
- pretty :: a -> Doc ann
- prettyList :: [a] -> Doc ann
- data Doc ann
- putDocLn :: Doc ann -> IO ()
- displayDoc :: Doc ann -> Text
- displayDocString :: Doc ann -> String
- docFromString :: String -> Doc ann
- docFromText :: Text -> Doc ann
- viaShow :: Show a => a -> Doc ann
- data MapEntry k v = k :-> v
- (-->) :: Pretty v => Text -> v -> MapEntry Text (Doc ann)
- ppMapEntryWith :: (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
- ppMapEntryWithSep :: Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
- ppList :: Pretty a => [a] -> Doc ann
- (##) :: Doc ann -> Doc ann -> Doc ann
- ppDictHeader :: Doc ann -> [MapEntry Text (Doc ann)] -> Doc ann
- ppDictAssocList :: [MapEntry Text (Doc ann)] -> Doc ann
- ppTuple :: Pretty a => [a] -> Doc ann
- ppTupleWith :: (a -> Doc ann) -> [a] -> Doc ann
- ppListWith :: (a -> Doc ann) -> [a] -> Doc ann
- ppFoldableHeader :: (Pretty a, Foldable f) => Doc ann -> f a -> Doc ann
- ppFoldableHeaderWith :: Foldable f => (a -> Doc ann) -> Doc ann -> f a -> Doc ann
- ppNE :: Pretty a => NonEmpty a -> Doc ann
- ppNEWith :: (a -> Doc ann) -> NonEmpty a -> Doc ann
- ppMap :: (Pretty a, Pretty b) => Map a b -> Doc ann
- ppMapWith :: (k -> Doc ann) -> (v -> Doc ann) -> Map k v -> Doc ann
- ppSet :: Pretty a => Set a -> Doc ann
- ppSetWith :: (a -> Doc ann) -> Set a -> Doc ann
- ppBimap :: (Pretty k, Pretty v) => Bimap k v -> Doc ann
- ppBimapWith :: (k -> Doc ann) -> (v -> Doc ann) -> Bimap k v -> Doc ann
- ppIntSet :: IntSet -> Doc ann
- ppIntSetWith :: (Int -> Doc ann) -> IntSet -> Doc ann
- ppIntMap :: Pretty a => IntMap a -> Doc ann
- ppIntMapWith :: (Int -> Doc ann) -> (a -> Doc ann) -> IntMap a -> Doc ann
- ppHashSet :: Pretty a => HashSet a -> Doc ann
- ppHashSetWith :: (a -> Doc ann) -> HashSet a -> Doc ann
- ppHashMap :: (Pretty k, Pretty v) => HashMap k v -> Doc ann
- ppHashMapWith :: (k -> Doc ann) -> (v -> Doc ann) -> HashMap k v -> Doc ann
- ppVector :: Pretty a => Vector a -> Doc ann
- ppVectorWith :: (a -> Doc ann) -> Vector a -> Doc ann
- ppDList :: Pretty a => DList a -> Doc ann
- ppDListWith :: (a -> Doc ann) -> DList a -> Doc ann
- ppListWithDelim :: forall f ann. Foldable f => Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
- ppAssocList :: (Pretty k, Pretty v) => [(k, v)] -> Doc ann
- ppAssocListWith :: (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
- ppAssocListWithSep :: Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
- ppByteString :: ByteString -> Doc ann
- ppByteStringLazy :: ByteString -> Doc ann
- ppShortByteString :: ShortByteString -> Doc ann
- ppTrace :: Doc ann -> a -> a
- ppCallStack :: CallStack -> Doc ann
- ppCallStackGHC :: CallStack -> Doc ann
Documentation
>>>
pretty 1 <+> pretty "hello" <+> pretty 1.234
1 hello 1.234
prettyList :: [a] -> Doc ann #
is only used to define the prettyList
instance
. In normal circumstances only the Pretty
a => Pretty
[a]
function is used.pretty
>>>
prettyList [1, 23, 456]
[1, 23, 456]
Instances
Pretty Bool |
|
Defined in Prettyprinter.Internal | |
Pretty Char | Instead of
|
Defined in Prettyprinter.Internal | |
Pretty Double |
|
Defined in Prettyprinter.Internal | |
Pretty Float |
|
Defined in Prettyprinter.Internal | |
Pretty Int |
|
Defined in Prettyprinter.Internal | |
Pretty Int8 | |
Defined in Prettyprinter.Internal | |
Pretty Int16 | |
Defined in Prettyprinter.Internal | |
Pretty Int32 | |
Defined in Prettyprinter.Internal | |
Pretty Int64 | |
Defined in Prettyprinter.Internal | |
Pretty Integer |
|
Defined in Prettyprinter.Internal | |
Pretty Natural | |
Defined in Prettyprinter.Internal | |
Pretty Word | |
Defined in Prettyprinter.Internal | |
Pretty Word8 | |
Defined in Prettyprinter.Internal | |
Pretty Word16 | |
Defined in Prettyprinter.Internal | |
Pretty Word32 | |
Defined in Prettyprinter.Internal | |
Pretty Word64 | |
Defined in Prettyprinter.Internal | |
Pretty () |
The argument is not used:
|
Defined in Prettyprinter.Internal | |
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.
|
Defined in Prettyprinter.Internal | |
Pretty Text | (lazy |
Defined in Prettyprinter.Internal | |
Pretty Text | Automatically converts all newlines to
Note that
Manually use |
Defined in Prettyprinter.Internal | |
Pretty a => Pretty [a] |
|
Defined in Prettyprinter.Internal | |
Pretty a => Pretty (Maybe a) | Ignore
|
Defined in Prettyprinter.Internal | |
Pretty a => Pretty (Identity a) |
|
Defined in Prettyprinter.Internal | |
Pretty a => Pretty (NonEmpty a) | |
Defined in Prettyprinter.Internal | |
(Pretty a1, Pretty a2) => Pretty (a1, a2) |
|
Defined in Prettyprinter.Internal | |
(Pretty k, Pretty v) => Pretty (MapEntry k v) Source # | |
Defined in Prettyprinter.Combinators | |
(Pretty a1, Pretty a2, Pretty a3) => Pretty (a1, a2, a3) |
|
Defined in Prettyprinter.Internal | |
Pretty a => Pretty (Const a b) | |
Defined in Prettyprinter.Internal |
The abstract data type
represents pretty documents that have
been annotated with data of type Doc
annann
.
More specifically, a value of type
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.Doc
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
displayDoc :: Doc ann -> Text Source #
displayDocString :: Doc ann -> String Source #
docFromString :: String -> Doc ann Source #
docFromText :: Text -> Doc ann Source #
viaShow :: Show a => a -> Doc ann #
Convenience function to convert a Show
able value to a Doc
. If the
String
does not contain newlines, consider using the more performant
unsafeViaShow
.
k :-> v infixr 0 |
Instances
Functor (MapEntry k) Source # | |
Foldable (MapEntry k) Source # | |
Defined in Prettyprinter.Combinators 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 # | |
Traversable (MapEntry k) Source # | |
Defined in Prettyprinter.Combinators | |
(Eq k, Eq v) => Eq (MapEntry k v) Source # | |
(Ord k, Ord v) => Ord (MapEntry k v) Source # | |
Defined in Prettyprinter.Combinators | |
(Show k, Show v) => Show (MapEntry k v) Source # | |
(Pretty k, Pretty v) => Pretty (MapEntry k v) Source # | |
Defined in Prettyprinter.Combinators |
(-->) :: Pretty v => Text -> v -> MapEntry Text (Doc ann) infixr 0 Source #
Helper to make constructing MapEntry
pairs easier by calling
pretty on value.
ppMapEntryWithSep :: Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann Source #
ppTupleWith :: (a -> Doc ann) -> [a] -> Doc ann Source #
ppListWith :: (a -> Doc ann) -> [a] -> Doc ann Source #
ppListWithDelim :: forall f ann. Foldable f => Doc ann -> Doc ann -> f (Doc ann) -> Doc ann Source #
ppByteString :: ByteString -> Doc ann Source #
ppByteStringLazy :: ByteString -> Doc ann Source #
ppShortByteString :: ShortByteString -> Doc ann Source #
ppCallStack :: CallStack -> Doc ann Source #
ppCallStackGHC :: CallStack -> Doc ann Source #
Pretty-print a CallStack just as GHC would.