Copyright | (C) 2014-2015 Ryan Scott |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Ryan Scott |
Stability | Experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell98 |
Efficiently convert from values to Text
via Builder
s.
Since: 0.1
- 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
- showbSpace :: Builder
- showbUnary :: Show a => Builder -> Int -> a -> Builder
- class Show1 f where
- showbPrec1 :: Show a => Int -> f a -> Builder
- showbUnary1 :: (Show1 f, Show a) => Builder -> Int -> f a -> Builder
- showbBinary1 :: (Show1 f, Show1 g, Show a) => Builder -> Int -> f a -> g a -> 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 ()
- newtype FromStringShow a = FromStringShow {
- fromStringShow :: a
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 Builder
s 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 <> showbSpace <> 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.
Since: 0.1
:: Int | The operator precedence of the enclosing context (a number
from |
-> a | The value to be converted to a |
-> Builder |
Convert a value to a Builder
with the given predence.
Since: 0.1
A specialized variant of showbPrec
using precedence context zero.
Since: 0.1
showbList :: [a] -> Builder Source
Allows for specialized display of lists. This is used, for example, when
showing lists of Char
s.
Since: 0.1
showPrec :: Show a => Int -> a -> Text Source
Constructs a strict Text
from a single value with the given precedence.
Since: 0.3
showPrecLazy :: Show a => Int -> a -> Text Source
Constructs a lazy Text
from a single value with the given precedence.
Since: 0.3
showListLazy :: Show a => [a] -> Text Source
Construct a lazy Text
from a list of values.
Since: 0.3.1
showbParen :: Bool -> Builder -> Builder Source
Construct a Builder
containing a single space character.
Since: 0.5
showbUnary :: Show a => Builder -> Int -> a -> Builder Source
produces the showbUnary
n p xBuilder
representation of a unary data
constructor with name n
and argument x
, in precedence context p
.
Since: 0.5
Lifting of the Show
class to unary type constructors.
Since: 0.5
showbPrec1 :: Show a => Int -> f a -> Builder Source
Builder
conversion for values of a type that has a unary type constructor.
Since: 0.5
showbUnary1 :: (Show1 f, Show a) => Builder -> Int -> f a -> Builder Source
produces the showbUnary1
n p xBuilder
representation of a unary data
constructor with name n
and argument x
, in precedence context p
.
Since: 0.5
showbBinary1 :: (Show1 f, Show1 g, Show a) => Builder -> Int -> f a -> g a -> Builder Source
produces the showbBinary1
n p x yBuilder
representation of a binary
data constructor with name n
and arguments x
and y
, in precedence
context p
.
Since: 0.5
Builder
s
module Data.Text.Lazy.Builder
replicateB :: Int64 -> Builder -> Builder Source
yields a replicateB
n bBuilder
containing b
repeated n
times.
Since: 0.3
unlinesB :: [Builder] -> Builder Source
Merges several Builder
s, separating them by newlines.
Since: 0.1
unwordsB :: [Builder] -> Builder Source
Merges several Builder
s, separating them by spaces.
Since: 0.1
Printing values
print :: Show a => a -> IO () Source
Writes a value's strict Text
representation to the standard output, followed
by a newline.
Since: 0.1
printLazy :: Show a => a -> IO () Source
Writes a value's lazy Text
representation to the standard output, followed
by a newline.
Since: 0.3
hPrint :: Show a => Handle -> a -> IO () Source
Writes a value's strict Text
representation to a file handle, followed
by a newline.
Since: 0.3
hPrintLazy :: Show a => Handle -> a -> IO () Source
Writes a value's lazy Text
representation to a file handle, followed
by a newline.
Since: 0.3
FromStringShow
newtype FromStringShow a Source
The Text
Show
instance for FromStringShow
is based on its String
Show
instance. That is,
showbPrec p (FromStringShow
x) =fromString
(showsPrec p x "")
Since: 0.5