Safe Haskell | None |
---|---|
Language | Haskell2010 |
Text.Printer
Description
Monoids with a homomorphism from String
to themselves.
Synopsis
- class (IsString p, Semigroup p, Monoid p) => Printer p where
- char :: Char -> p
- char7 :: Char -> p
- string :: String -> p
- string7 :: String -> p
- text :: Text -> p
- lazyText :: Text -> p
- ascii :: ByteString -> p
- lazyAscii :: ByteString -> p
- utf8 :: ByteString -> p
- lazyUtf8 :: ByteString -> p
- newtype StringBuilder = StringBuilder {
- stringBuilder :: String -> String
- buildString :: StringBuilder -> String
- buildText :: Builder -> Text
- buildLazyText :: Builder -> Text
- newtype AsciiBuilder = AsciiBuilder {}
- buildAscii :: AsciiBuilder -> ByteString
- buildLazyAscii :: AsciiBuilder -> ByteString
- newtype Utf8Builder = Utf8Builder {}
- buildUtf8 :: Utf8Builder -> ByteString
- buildLazyUtf8 :: Utf8Builder -> ByteString
- newtype PrettyPrinter = PrettyPrinter {
- prettyPrinter :: Doc
- renderPretty :: PrettyPrinter -> String
- (<>) :: Semigroup a => a -> a -> a
- hcat :: (Printer p, Foldable f) => f p -> p
- fcat :: (Foldable f, Printer p) => (p -> p -> p) -> f p -> p
- separate :: Printer p => p -> p -> p -> p
- (<+>) :: Printer p => p -> p -> p
- hsep :: (Printer p, Foldable f) => f p -> p
- fsep :: (Foldable f, Printer p) => p -> f p -> p
- list :: (Foldable f, Printer p) => f p -> p
- parens :: Printer p => p -> p
- brackets :: Printer p => p -> p
- braces :: Printer p => p -> p
- angles :: Printer p => p -> p
- squotes :: Printer p => p -> p
- dquotes :: Printer p => p -> p
- punctuateL :: (Traversable t, Printer p) => p -> t p -> t p
- punctuateR :: (Traversable t, Printer p) => p -> t p -> t p
- class Printer p => MultilinePrinter p where
- (<->) :: p -> p -> p
- lines :: (MultilinePrinter p, Foldable f) => f p -> p
- newLine :: Printer p => p
- crlf :: Printer p => p
- newtype LinePrinter p = LinePrinter {
- linePrinter :: (p -> p -> p) -> p
- lfPrinter :: Printer p => LinePrinter p -> p
- crlfPrinter :: Printer p => LinePrinter p -> p
The class
class (IsString p, Semigroup p, Monoid p) => Printer p where Source #
Text monoid. string
must be equivalent to fromString
and be a monoid
homomorphism, i.e.
and
string
mempty
= mempty
.
Other operations must be monoid homomorphisms that are eqiuvalent (but
possibly faster) to the composition of mappend
(string
x) (string
y) = string
(mappend
x y)string
and the corresponding
embedding, e.g.
.text
= string
. unpack
Minimal complete definition
Nothing
Methods
Print an ASCII character, can be faster than char
.
string :: String -> p Source #
Print a string.
string7 :: String -> p Source #
Print an ASCII string, can be faster than string
.
Print a Text
.
lazyText :: Text -> p Source #
Print a lazy Text
.
ascii :: ByteString -> p Source #
Print an ASCII ByteString
.
lazyAscii :: ByteString -> p Source #
Print a lazy ASCII ByteString
.
utf8 :: ByteString -> p Source #
Print a UTF-8 ByteString
.
lazyUtf8 :: ByteString -> p Source #
Print a lazy UTF-8 ByteString
Instances
Builders
newtype StringBuilder Source #
A simple string builder as used by Show
.
Constructors
StringBuilder | |
Fields
|
Instances
buildString :: StringBuilder -> String Source #
buildLazyText :: Builder -> Text Source #
newtype AsciiBuilder Source #
Use this builder when you are sure that only ASCII characters will get printed to it.
Constructors
AsciiBuilder | |
Fields |
Instances
IsString AsciiBuilder Source # | |||||
Defined in Text.Printer Methods fromString :: String -> AsciiBuilder # | |||||
Monoid AsciiBuilder Source # | |||||
Defined in Text.Printer Methods mempty :: AsciiBuilder # mappend :: AsciiBuilder -> AsciiBuilder -> AsciiBuilder # mconcat :: [AsciiBuilder] -> AsciiBuilder # | |||||
Semigroup AsciiBuilder Source # | |||||
Defined in Text.Printer Methods (<>) :: AsciiBuilder -> AsciiBuilder -> AsciiBuilder # sconcat :: NonEmpty AsciiBuilder -> AsciiBuilder # stimes :: Integral b => b -> AsciiBuilder -> AsciiBuilder # | |||||
Generic AsciiBuilder Source # | |||||
Defined in Text.Printer Associated Types
| |||||
Printer AsciiBuilder Source # | |||||
Defined in Text.Printer Methods char :: Char -> AsciiBuilder Source # char7 :: Char -> AsciiBuilder Source # string :: String -> AsciiBuilder Source # string7 :: String -> AsciiBuilder Source # text :: Text -> AsciiBuilder Source # lazyText :: Text -> AsciiBuilder Source # ascii :: ByteString -> AsciiBuilder Source # lazyAscii :: ByteString -> AsciiBuilder Source # utf8 :: ByteString -> AsciiBuilder Source # lazyUtf8 :: ByteString -> AsciiBuilder Source # | |||||
type Rep AsciiBuilder Source # | |||||
Defined in Text.Printer type Rep AsciiBuilder = D1 ('MetaData "AsciiBuilder" "Text.Printer" "text-printer-0.5.0.2-ItozbxLO2rILLRCIkSOMtd" 'True) (C1 ('MetaCons "AsciiBuilder" 'PrefixI 'True) (S1 ('MetaSel ('Just "asciiBuilder") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Builder))) |
buildAscii :: AsciiBuilder -> ByteString Source #
newtype Utf8Builder Source #
UTF-8 lazy ByteString
builder.
Constructors
Utf8Builder | |
Fields |
Instances
IsString Utf8Builder Source # | |||||
Defined in Text.Printer Methods fromString :: String -> Utf8Builder # | |||||
Monoid Utf8Builder Source # | |||||
Defined in Text.Printer Methods mempty :: Utf8Builder # mappend :: Utf8Builder -> Utf8Builder -> Utf8Builder # mconcat :: [Utf8Builder] -> Utf8Builder # | |||||
Semigroup Utf8Builder Source # | |||||
Defined in Text.Printer Methods (<>) :: Utf8Builder -> Utf8Builder -> Utf8Builder # sconcat :: NonEmpty Utf8Builder -> Utf8Builder # stimes :: Integral b => b -> Utf8Builder -> Utf8Builder # | |||||
Generic Utf8Builder Source # | |||||
Defined in Text.Printer Associated Types
| |||||
Printer Utf8Builder Source # | |||||
Defined in Text.Printer Methods char :: Char -> Utf8Builder Source # char7 :: Char -> Utf8Builder Source # string :: String -> Utf8Builder Source # string7 :: String -> Utf8Builder Source # text :: Text -> Utf8Builder Source # lazyText :: Text -> Utf8Builder Source # ascii :: ByteString -> Utf8Builder Source # lazyAscii :: ByteString -> Utf8Builder Source # utf8 :: ByteString -> Utf8Builder Source # lazyUtf8 :: ByteString -> Utf8Builder Source # | |||||
type Rep Utf8Builder Source # | |||||
Defined in Text.Printer type Rep Utf8Builder = D1 ('MetaData "Utf8Builder" "Text.Printer" "text-printer-0.5.0.2-ItozbxLO2rILLRCIkSOMtd" 'True) (C1 ('MetaCons "Utf8Builder" 'PrefixI 'True) (S1 ('MetaSel ('Just "utf8Builder") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Builder))) |
buildUtf8 :: Utf8Builder -> ByteString Source #
newtype PrettyPrinter Source #
Constructors
PrettyPrinter | |
Fields
|
Instances
IsString PrettyPrinter Source # | |||||
Defined in Text.Printer Methods fromString :: String -> PrettyPrinter # | |||||
Monoid PrettyPrinter Source # | |||||
Defined in Text.Printer Methods mempty :: PrettyPrinter # mappend :: PrettyPrinter -> PrettyPrinter -> PrettyPrinter # mconcat :: [PrettyPrinter] -> PrettyPrinter # | |||||
Semigroup PrettyPrinter Source # | |||||
Defined in Text.Printer Methods (<>) :: PrettyPrinter -> PrettyPrinter -> PrettyPrinter # sconcat :: NonEmpty PrettyPrinter -> PrettyPrinter # stimes :: Integral b => b -> PrettyPrinter -> PrettyPrinter # | |||||
Generic PrettyPrinter Source # | |||||
Defined in Text.Printer Associated Types
| |||||
MultilinePrinter PrettyPrinter Source # | |||||
Defined in Text.Printer Methods (<->) :: PrettyPrinter -> PrettyPrinter -> PrettyPrinter Source # | |||||
Printer PrettyPrinter Source # | |||||
Defined in Text.Printer Methods char :: Char -> PrettyPrinter Source # char7 :: Char -> PrettyPrinter Source # string :: String -> PrettyPrinter Source # string7 :: String -> PrettyPrinter Source # text :: Text -> PrettyPrinter Source # lazyText :: Text -> PrettyPrinter Source # ascii :: ByteString -> PrettyPrinter Source # lazyAscii :: ByteString -> PrettyPrinter Source # utf8 :: ByteString -> PrettyPrinter Source # lazyUtf8 :: ByteString -> PrettyPrinter Source # | |||||
type Rep PrettyPrinter Source # | |||||
Defined in Text.Printer type Rep PrettyPrinter = D1 ('MetaData "PrettyPrinter" "Text.Printer" "text-printer-0.5.0.2-ItozbxLO2rILLRCIkSOMtd" 'True) (C1 ('MetaCons "PrettyPrinter" 'PrefixI 'True) (S1 ('MetaSel ('Just "prettyPrinter") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Doc))) |
renderPretty :: PrettyPrinter -> String Source #
An alias for render
. prettyPrinter
Combinators
(<>) :: Semigroup a => a -> a -> a infixr 6 #
An associative operation.
Examples
>>>
[1,2,3] <> [4,5,6]
[1,2,3,4,5,6]
>>>
Just [1, 2, 3] <> Just [4, 5, 6]
Just [1,2,3,4,5,6]
>>>
putStr "Hello, " <> putStrLn "World!"
Hello, World!
Arguments
:: Printer p | |
=> p | The separator |
-> p | |
-> p | |
-> p |
Concatenate two Printer
s with a separator between them.
(<+>) :: Printer p => p -> p -> p infixr 6 Source #
Concatenate two Printer
s with a space between them.
hsep :: (Printer p, Foldable f) => f p -> p Source #
Concatenate the items of a Foldable
data structure
with spaces between them.
punctuateL :: (Traversable t, Printer p) => p -> t p -> t p Source #
Prepend all but the first element of a Traversable
with the
provided value, e.g.
punctuateL
p [x1, x2, ..., xN] =
[x1, p <>
x2, ..., p <>
xN]
punctuateR :: (Traversable t, Printer p) => p -> t p -> t p Source #
Append the provided value to all but the last element of a Traversable
,
e.g. punctuateR
p [x1, ..., xN-1, xN] =
[x1 <>
p, ..., xN-1 <>
p, xN]
Multiline printers
class Printer p => MultilinePrinter p where Source #
Printers that can produce multiple lines of text.
Methods
Instances
MultilinePrinter PrettyPrinter Source # | |
Defined in Text.Printer Methods (<->) :: PrettyPrinter -> PrettyPrinter -> PrettyPrinter Source # | |
Printer p => MultilinePrinter (LinePrinter p) Source # | |
Defined in Text.Printer Methods (<->) :: LinePrinter p -> LinePrinter p -> LinePrinter p Source # |
lines :: (MultilinePrinter p, Foldable f) => f p -> p Source #
newtype LinePrinter p Source #
A multiline printer that combines lines with the provided function.
Constructors
LinePrinter | |
Fields
|
Instances
IsString p => IsString (LinePrinter p) Source # | |||||
Defined in Text.Printer Methods fromString :: String -> LinePrinter p # | |||||
Monoid p => Monoid (LinePrinter p) Source # | |||||
Defined in Text.Printer Methods mempty :: LinePrinter p # mappend :: LinePrinter p -> LinePrinter p -> LinePrinter p # mconcat :: [LinePrinter p] -> LinePrinter p # | |||||
Semigroup p => Semigroup (LinePrinter p) Source # | |||||
Defined in Text.Printer Methods (<>) :: LinePrinter p -> LinePrinter p -> LinePrinter p # sconcat :: NonEmpty (LinePrinter p) -> LinePrinter p # stimes :: Integral b => b -> LinePrinter p -> LinePrinter p # | |||||
Generic (LinePrinter p) Source # | |||||
Defined in Text.Printer Associated Types
Methods from :: LinePrinter p -> Rep (LinePrinter p) x # to :: Rep (LinePrinter p) x -> LinePrinter p # | |||||
Printer p => MultilinePrinter (LinePrinter p) Source # | |||||
Defined in Text.Printer Methods (<->) :: LinePrinter p -> LinePrinter p -> LinePrinter p Source # | |||||
Printer p => Printer (LinePrinter p) Source # | |||||
Defined in Text.Printer Methods char :: Char -> LinePrinter p Source # char7 :: Char -> LinePrinter p Source # string :: String -> LinePrinter p Source # string7 :: String -> LinePrinter p Source # text :: Text -> LinePrinter p Source # lazyText :: Text -> LinePrinter p Source # ascii :: ByteString -> LinePrinter p Source # lazyAscii :: ByteString -> LinePrinter p Source # utf8 :: ByteString -> LinePrinter p Source # lazyUtf8 :: ByteString -> LinePrinter p Source # | |||||
type Rep (LinePrinter p) Source # | |||||
Defined in Text.Printer type Rep (LinePrinter p) = D1 ('MetaData "LinePrinter" "Text.Printer" "text-printer-0.5.0.2-ItozbxLO2rILLRCIkSOMtd" 'True) (C1 ('MetaCons "LinePrinter" 'PrefixI 'True) (S1 ('MetaSel ('Just "linePrinter") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ((p -> p -> p) -> p)))) |
crlfPrinter :: Printer p => LinePrinter p -> p Source #
Separate lines with crlf
.