| Copyright | (C) 2014 Ryan Scott |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Ryan Scott |
| Stability | Experimental |
| Portability | GHC |
| Safe Haskell | None |
| Language | Haskell98 |
Text.Show.Text
Description
Efficiently convert from values to Text via Builders.
- class Show a where
- show :: Show a => a -> Text
- showLazy :: Show a => a -> Text
- showPrec :: Show a => Int -> a -> Text
- showPrecLazy :: Show a => Int -> a -> Text
- showList :: Show a => [a] -> Text
- showListLazy :: Show a => [a] -> Text
- showbParen :: Bool -> Builder -> Builder
- module Data.Text.Lazy.Builder
- toString :: Builder -> String
- toText :: Builder -> Text
- lengthB :: Builder -> Int64
- replicateB :: Int64 -> Builder -> Builder
- unlinesB :: [Builder] -> Builder
- unwordsB :: [Builder] -> Builder
- print :: Show a => a -> IO ()
- printLazy :: Show a => a -> IO ()
- hPrint :: Show a => Handle -> a -> IO ()
- hPrintLazy :: Show a => Handle -> a -> IO ()
The Show class
Conversion of values to Text. Because there are both strict and lazy Text
variants, the Show class deliberately avoids using Text in its functions.
Instead, showbPrec, showb, and showbList all return Builder, an
efficient intermediate form that can be converted to either kind of Text.
Builder is a Monoid, so it is useful to use the mappend (or <>) function
to combine Builders when creating Show instances. As an example:
import Text.Show.Text
data Example = Example Int Int
instance Show Example where
showb (Example i1 i2) = showb i1 <> singleton ' ' <> showb i2
If you do not want to create Show instances manually, you can alternatively
use the Text.Show.Text.TH module to automatically generate default Show
instances using Template Haskell.
Methods
showbPrec :: Int -> a -> Builder Source
Constructs a Text via an efficient Builder. The precedence is used to
determine where to put parentheses in a shown expression involving operators.
Builders can be efficiently combined, so the showb functions are available
for showing multiple values before producing an output Text.
Constructs a Text via an efficient Builder. Builders can be efficiently
combined, so this is available building a Text from multiple values.
showbList :: [a] -> Builder Source
Allows for specialized display of lists. This is used, for example, when
showing lists of Chars.
Instances
showPrec :: Show a => Int -> a -> Text Source
Constructs a strict Text from a single value with the given precedence.
showPrecLazy :: Show a => Int -> a -> Text Source
Constructs a lazy Text from a single value with the given precedence.
showListLazy :: Show a => [a] -> Text Source
Construct a lazy Text from a list of values.
showbParen :: Bool -> Builder -> Builder Source
Builders
module Data.Text.Lazy.Builder
replicateB :: Int64 -> Builder -> Builder Source
yields a replicateB n bBuilder containing b repeated n times.
Printing values
print :: Show a => a -> IO () Source
Writes a value's strict Text representation to the standard output, followed
by a newline.
printLazy :: Show a => a -> IO () Source
Writes a value's lazy Text representation to the standard output, followed
by a newline.