Text.Show.ByteString

bytestring-show-0.3.5.5: Efficient conversion of values into readable byte strings.

Portability | Non-portable (type synonym instances)
Stability | Experimental
Maintainer | Dan Doel
Safe Haskell | None

Text.Show.ByteString

Contents

- The Show class
- Putting Chars
- Putting Strings
- Putting digits
- Putting integers
- Putting floats
- Combining builders
- Printing values
- Put

Description

Efficiently convert from values to lazy byte strings.

Synopsis

- class Show a where
  - showpPrec :: Int -> a -> Put
  - showp :: a -> Put
  - showpList :: [a] -> Put
- show :: Show a => a -> ByteString
- putAscii :: Char -> Put
- putUTF8 :: Char -> Put
- putAsciiStr :: String -> Put
- putUTF8Str :: String -> Put
- unsafePutDigit :: Int -> Put
- putDigit :: Int -> Put
- showpIntAtBase :: Integral a => a -> (Int -> Char) -> a -> Put
- showpGFloat :: RealFloat a => Maybe Int -> a -> Put
- showpFFloat :: RealFloat a => Maybe Int -> a -> Put
- showpEFloat :: RealFloat a => Maybe Int -> a -> Put
- unlinesP :: [Put] -> Put
- unwordsP :: [Put] -> Put
- showpParen :: Bool -> Put -> Put
- print :: Show a => a -> IO ()
- type Put = PutM ()
- newtype PutM a = Put {
  - unPut :: PairS a
  }
- runPut :: Put -> ByteString

# The Show class

class Show a where

Conversion of values to readable byte strings. Minimal complete definition: `showp` or `showpPrec`

Methods

showpPrec :: Int -> a -> Put

Encodes a value to an efficient byte string builder. The precedence is used to determine where to put parentheses in a shown expression involving operators.

Values of type Put can be efficiently combined, so the showp functions are available for showing multiple values before producing an output byte string.

showp :: a -> Put

Encodes a value to an efficient byte string builder. Values of type Put can be efficiently combined, so this is available for building strings from multiple values.

showpList :: [a] -> Put

Allows for specialized display of lists of values. This is used, for example, when showing arrays of Chars.

Instances

Show Bool |
Show Char |
Show Double |
Show Float |
Show Int |
Show Int8 |
Show Int16 |
Show Int32 |
Show Int64 |
Show Integer |
Show Ordering |
Show Word |
Show Word8 |
Show Word16 |
Show Word32 |
Show Word64 |
Show () |
Show Put |
Show a => Show [a] |
(Show a, Integral a) => Show (Ratio a) |
(Show a, RealFloat a) => Show (Complex a) |
Show a => Show (Maybe a) |
Show e => Show (Set e) |
(Show a, Show b) => Show (Either a b) |
(Show a, Show b) => Show (a, b) |
(Show i, Show e, Ix i) => Show (Array i e) |
(Show k, Show v) => Show (Map k v) |
(Show a, Show b, Show c) => Show (a, b, c) |
(Show a, Show b, Show c, Show d) => Show (a, b, c, d) |
(Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) |
(Show a, Show b, Show c, Show d, Show e, Show f) => Show (a, b, c, d, e, f) |
(Show a, Show b, Show c, Show d, Show e, Show f, Show g) => Show (a, b, c, d, e, f, g) |

show :: Show a => a -> ByteString

Encode a single value into a byte string

# Putting Chars

putAscii :: Char -> Put

Writes a single Char to a byte string, assuming it's ascii.

putUTF8 :: Char -> Put

Writes a single Char to a byte string, properly UTF-8 encoded

# Putting Strings

putAsciiStr :: String -> Put

Writes a string of ascii characters to a byte string

putUTF8Str :: String -> Put

Writes a string of unicode characters to a byte string, properly UTF-8 encoded

# Putting digits

unsafePutDigit :: Int -> Put

Puts the decimal digit corresponding to the given Int without checking that it is in the interval [0,9]

putDigit :: Int -> Put

Puts the digit corresponding to the Int passed in.

# Putting integers

showpIntAtBase :: Integral a => a -> (Int -> Char) -> a -> Put

Shows an Integral number using the base specified by the first argument and the chracter representation specified by the second.

# Putting floats

showpGFloat :: RealFloat a => Maybe Int -> a -> Put

Show a signed RealFloat value using decimal notation when the absolute value lies between 0.1 and 9,999,999, and scientific notation otherwise. The optional integer can be used to specify precision.

showpFFloat :: RealFloat a => Maybe Int -> a -> Put

Show a signed RealFloat value using decimal notation. The optional integer can be used to specify precision.

showpEFloat :: RealFloat a => Maybe Int -> a -> Put

Show a signed RealFloat value using scientific (exponential) notation. The optional integer can be used to specify precision.

# Combining builders

unlinesP :: [Put] -> Put

Merge several string builders, separating them by newlines

unwordsP :: [Put] -> Put

Merge several string builders, separating them by spaces

showpParen :: Bool -> Put -> Put

A utility function for surrounding output by parentheses conditionally.

# Printing values

print :: Show a => a -> IO ()

Print a value to the standard output

# Put

type Put = PutM ()

Put merely lifts Builder into a Writer monad, applied to ().

newtype PutM a

The PutM type. A Writer monad over the efficient Builder monoid.

Constructors

Put |
Fields unPut :: PairS a

Instances

Monad PutM |
Functor PutM |
Applicative PutM |
Show Put |

runPut :: Put -> ByteString

Run the `Put` monad with a serialiser