Text.Show.ByteString

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

Copyright | (c) 2008 Dan Doel
Maintainer | Dan Doel
Stability | Experimental
Portability | Non-portable (type synonym instances)
Safe Haskell | None
Language | Haskell98

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
- 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 # |
Methods showpPrec :: Int -> Bool -> Put # showp :: Bool -> Put # showpList :: [Bool] -> Put #
Show Char # |
Methods showpPrec :: Int -> Char -> Put # showp :: Char -> Put # showpList :: [Char] -> Put #
Show Double # |
Methods showpPrec :: Int -> Double -> Put # showp :: Double -> Put # showpList :: [Double] -> Put #
Show Float # |
Methods showpPrec :: Int -> Float -> Put # showp :: Float -> Put # showpList :: [Float] -> Put #
Show Int # |
Methods showpPrec :: Int -> Int -> Put # showp :: Int -> Put # showpList :: [Int] -> Put #
Show Int8 # |
Methods showpPrec :: Int -> Int8 -> Put # showp :: Int8 -> Put # showpList :: [Int8] -> Put #
Show Int16 # |
Methods showpPrec :: Int -> Int16 -> Put # showp :: Int16 -> Put # showpList :: [Int16] -> Put #
Show Int32 # |
Methods showpPrec :: Int -> Int32 -> Put # showp :: Int32 -> Put # showpList :: [Int32] -> Put #
Show Int64 # |
Methods showpPrec :: Int -> Int64 -> Put # showp :: Int64 -> Put # showpList :: [Int64] -> Put #
Show Integer # |
Methods showpPrec :: Int -> Integer -> Put # showp :: Integer -> Put # showpList :: [Integer] -> Put #
Show Ordering # |
Methods showpPrec :: Int -> Ordering -> Put # showp :: Ordering -> Put # showpList :: [Ordering] -> Put #
Show Word # |
Methods showpPrec :: Int -> Word -> Put # showp :: Word -> Put # showpList :: [Word] -> Put #
Show Word8 # |
Methods showpPrec :: Int -> Word8 -> Put # showp :: Word8 -> Put # showpList :: [Word8] -> Put #
Show Word16 # |
Methods showpPrec :: Int -> Word16 -> Put # showp :: Word16 -> Put # showpList :: [Word16] -> Put #
Show Word32 # |
Methods showpPrec :: Int -> Word32 -> Put # showp :: Word32 -> Put # showpList :: [Word32] -> Put #
Show Word64 # |
Methods showpPrec :: Int -> Word64 -> Put # showp :: Word64 -> Put # showpList :: [Word64] -> Put #
Show () # |
Methods showpPrec :: Int -> () -> Put # showp :: () -> Put # showpList :: [()] -> Put #
Show Put # |
Methods showpPrec :: Int -> Put -> Put # showp :: Put -> Put # showpList :: [Put] -> Put #
Show a => Show [a] # |
Methods showpPrec :: Int -> [a] -> Put # showp :: [a] -> Put # showpList :: [[a]] -> Put #
Show a => Show (Maybe a) # |
Methods showpPrec :: Int -> Maybe a -> Put # showp :: Maybe a -> Put # showpList :: [Maybe a] -> Put #
(Show a, Integral a) => Show (Ratio a) # |
Methods showpPrec :: Int -> Ratio a -> Put # showp :: Ratio a -> Put # showpList :: [Ratio a] -> Put #
(Show a, RealFloat a) => Show (Complex a) # |
Methods showpPrec :: Int -> Complex a -> Put # showp :: Complex a -> Put # showpList :: [Complex a] -> Put #
Show e => Show (Set e) # |
Methods showpPrec :: Int -> Set e -> Put # showp :: Set e -> Put # showpList :: [Set e] -> Put #
(Show a, Show b) => Show (Either a b) # |
Methods showpPrec :: Int -> Either a b -> Put # showp :: Either a b -> Put # showpList :: [Either a b] -> Put #
(Show a, Show b) => Show (a, b) # |
Methods showpPrec :: Int -> (a, b) -> Put # showp :: (a, b) -> Put # showpList :: [(a, b)] -> Put #
(Show i, Show e, Ix i) => Show (Array i e) # |
Methods showpPrec :: Int -> Array i e -> Put # showp :: Array i e -> Put # showpList :: [Array i e] -> Put #
(Show k, Show v) => Show (Map k v) # |
Methods showpPrec :: Int -> Map k v -> Put # showp :: Map k v -> Put # showpList :: [Map k v] -> Put #
(Show a, Show b, Show c) => Show (a, b, c) # |
Methods showpPrec :: Int -> (a, b, c) -> Put # showp :: (a, b, c) -> Put # showpList :: [(a, b, c)] -> Put #
(Show a, Show b, Show c, Show d) => Show (a, b, c, d) # |
Methods showpPrec :: Int -> (a, b, c, d) -> Put # showp :: (a, b, c, d) -> Put # showpList :: [(a, b, c, d)] -> Put #
(Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) # |
Methods showpPrec :: Int -> (a, b, c, d, e) -> Put # showp :: (a, b, c, d, e) -> Put # showpList :: [(a, b, c, d, e)] -> Put #
(Show a, Show b, Show c, Show d, Show e, Show f) => Show (a, b, c, d, e, f) # |
Methods showpPrec :: Int -> (a, b, c, d, e, f) -> Put # showp :: (a, b, c, d, e, f) -> Put # showpList :: [(a, b, c, d, e, f)] -> Put #
(Show a, Show b, Show c, Show d, Show e, Show f, Show g) => Show (a, b, c, d, e, f, g) # |
Methods showpPrec :: Int -> (a, b, c, d, e, f, g) -> Put # showp :: (a, b, c, d, e, f, g) -> Put # showpList :: [(a, b, c, d, e, f, g)] -> Put #

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 |
Methods (>>=) :: PutM a -> (a -> PutM b) -> PutM b # (>>) :: PutM a -> PutM b -> PutM b # return :: a -> PutM a # fail :: String -> PutM a #
Functor PutM |
Methods fmap :: (a -> b) -> PutM a -> PutM b # (<$) :: a -> PutM b -> PutM a #
Applicative PutM |
Methods pure :: a -> PutM a # (<*>) :: PutM (a -> b) -> PutM a -> PutM b # (*>) :: PutM a -> PutM b -> PutM b # (<*) :: PutM a -> PutM b -> PutM a #
Show Put # |
Methods showpPrec :: Int -> Put -> Put # showp :: Put -> Put # showpList :: [Put] -> Put #
Semigroup (PutM ()) |
Methods (<>) :: PutM () -> PutM () -> PutM () # sconcat :: NonEmpty (PutM ()) -> PutM () # stimes :: Integral b => b -> PutM () -> PutM () #
Monoid (PutM ()) |
Methods mempty :: PutM () # mappend :: PutM () -> PutM () -> PutM () # mconcat :: [PutM ()] -> PutM () #

runPut :: Put -> ByteString #

Run the `Put` monad with a serialiser