text-show-0.6.0.1: Efficient conversion of values into Text

Copyright(C) 2014-2015 Ryan Scott
LicenseBSD-style (see the file LICENSE)
MaintainerRyan Scott
StabilityExperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell98

Text.Show.Text

Contents

Description

Efficiently convert from values to Text via Builders.

Since: 0.1

Synopsis

The Show class

class Show a where Source

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 <> 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, or the Text.Show.Text.Generic module to quickly define Show instances using genericShowbPrec.

Since: 0.1

Minimal complete definition

showbPrec | showb

Methods

showbPrec Source

Arguments

:: Int

The operator precedence of the enclosing context (a number from 0 to 11). Function application has precedence 10.

-> a

The value to be converted to a String.

-> Builder 

Convert a value to a Builder with the given predence.

Since: 0.1

showb :: a -> Builder Source

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 Chars.

Since: 0.1

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 Handle 
Show GCStats 
Show DataType 
Show Constr 
Show DataRep 
Show ConstrRep 
Show Fixity 
Show Version 
Show SomeNat 
Show SomeSymbol 
Show TypeRep 
Show TyCon 
Show HandlePosn 
Show FdKey 
Show Event 
Show IOMode 
Show PatternMatchFail 
Show RecSelError 
Show RecConError 
Show RecUpdError 
Show NoMethodError 
Show NonTermination 
Show NestedAtomically 
Show ThreadId 
Show BlockReason 
Show ThreadStatus 
Show CodingFailureMode 
Show CDev 
Show CIno 
Show CMode 
Show COff 
Show CPid 
Show CSsize 
Show CGid 
Show CNlink 
Show CUid 
Show CCc 
Show CSpeed 
Show CTcflag 
Show CRLim 
Show Fd 
Show BlockedIndefinitelyOnMVar 
Show BlockedIndefinitelyOnSTM 
Show Deadlock 
Show AssertionFailed 
Show SomeAsyncException 
Show AsyncException 
Show ArrayException 
Show ExitCode 
Show BufferMode 
Show Newline 
Show NewlineMode 
Show SeekMode 
Show TextEncoding 
Show CodingProgress 
Show WordPtr 
Show IntPtr 
Show GeneralCategory 
Show CChar 
Show CSChar 
Show CUChar 
Show CShort 
Show CUShort 
Show CInt 
Show CUInt 
Show CLong 
Show CULong 
Show CLLong 
Show CULLong 
Show CFloat 
Show CDouble 
Show CPtrdiff 
Show CSize 
Show CWchar 
Show CSigAtomic 
Show CClock 
Show CTime 
Show CUSeconds 
Show CSUSeconds 
Show CIntPtr 
Show CUIntPtr 
Show CIntMax 
Show CUIntMax 
Show Dynamic 
Show MaskingState 
Show IOException 
Show ErrorCall 
Show ArithException 
Show All 
Show Any 
Show Arity 
Show Fixity 
Show Associativity 
Show TypeRep 
Show TyCon 
Show Fingerprint 
Show Lexeme 
Show Number 
Show SomeException 
Show ByteString 
Show ShortByteString 
Show ByteString 
Show Natural 
Show Builder 
Show Text 
Show Text 
Show Void 
Show LitString 
Show LitChar 
Show ConType 
Show a => Show [a] 
(Show a, Integral a) => Show (Ratio a) 
Show (Ptr a) 
Show (FunPtr a) 
Show (U1 p) 
Show p0 => Show (Par1 p) 
Show (ForeignPtr a) 
HasResolution a => Show (Fixed a) 
Show a0 => Show (Complex a) 
Show a0 => Show (ZipList a) 
Show a0 => Show (Dual a) 
Show a0 => Show (Sum a) 
Show a0 => Show (Product a) 
Show a0 => Show (First a) 
Show a0 => Show (Last a) 
Show a0 => Show (Down a) 
Show a0 => Show (Maybe a) 
Show a => Show (Identity a) 
Show a => Show (FromTextShow a) 
Show a => Show (FromStringShow a) 
Show (a -> b) 
(Show a0, Show b0) => Show (Either a b) 
Show (f p) => Show (Rec1 f p) 
(Show a0, Show b0) => Show (a, b) 
Show (ST s a) 
(Show i, Show e, Ix i) => Show (Array i e) 
Show (Proxy * s) 
Show c => Show (K1 i c p) 
(Show (f p), Show (g p)) => Show ((:+:) f g p) 
(Show (f p), Show (g p)) => Show ((:*:) f g p) 
Show (f (g p)) => Show ((:.:) f g p) 
(Show a0, Show b0, Show c0) => Show (a, b, c) 
Show (Coercion * a b) 
Show ((:~:) * a b) 
Show (f p) => Show (M1 i c f p) 
(Show a0, Show b0, Show c0, Show d0) => Show (a, b, c, d) 
(Show a0, Show b0, Show c0, Show d0, Show e0) => Show (a, b, c, d, e) 
(Show a0, Show b0, Show c0, Show d0, Show e0, Show f0) => Show (a, b, c, d, e, f) 
(Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0) => Show (a, b, c, d, e, f, g) 
(Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0) => Show (a, b, c, d, e, f, g, h) 
(Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0) => Show (a, b, c, d, e, f, g, h, i) 
(Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0) => Show (a, b, c, d, e, f, g, h, i, j) 
(Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0) => Show (a, b, c, d, e, f, g, h, i, j, k) 
(Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0) => Show (a, b, c, d, e, f, g, h, i, j, k, l) 
(Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0, Show m0) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m) 
(Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0, Show m0, Show n0) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n) 
(Show a0, Show b0, Show c0, Show d0, Show e0, Show f0, Show g0, Show h0, Show i0, Show j0, Show k0, Show l0, Show m0, Show n0, Show o0) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) 

show :: Show a => a -> Text Source

Constructs a strict Text from a single value.

Since: 0.1

showLazy :: Show a => a -> Text Source

Constructs a lazy Text from a single value.

Since: 0.3

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

showList :: Show a => [a] -> Text Source

Construct a strict Text from a list of values.

Since: 0.3.1

showListLazy :: Show a => [a] -> Text Source

Construct a lazy Text from a list of values.

Since: 0.3.1

showbParen :: Bool -> Builder -> Builder Source

Surrounds Builder output with parentheses if the Bool parameter is True.

Since: 0.1

showbSpace :: Builder Source

Construct a Builder containing a single space character.

Since: 0.5

showbUnary :: Show a => Builder -> Int -> a -> Builder Source

showbUnary n p x produces the Builder representation of a unary data constructor with name n and argument x, in precedence context p.

Since: 0.5

class Show1 f where Source

Lifting of the Show class to unary type constructors.

Since: 0.5

Methods

showbPrec1 :: Show a => Int -> f a -> Builder Source

Builder conversion for values of a type that has a unary type constructor.

Since: 0.5

Instances

Show1 [] 
Show1 Ptr 
Show1 FunPtr 
Show1 U1 
Show1 Par1 
Show1 ForeignPtr 
Show1 Complex 
Show1 ZipList 
Show1 Dual 
Show1 Sum 
Show1 Product 
Show1 First 
Show1 Last 
Show1 Down 
Show1 Maybe 
Show1 Identity 
Show1 FromTextShow 
Show1 ((->) a) 
Show a => Show1 (Either a) 
Show a => Show1 ((,) a) 
Show1 (ST s) 
Show1 (Proxy *) 
Show c => Show1 (K1 i c) 
(Show a, Show b) => Show1 ((,,) a b) 
Show1 (Coercion * a) 
Show1 ((:~:) * a) 
(Show a, Show b, Show c) => Show1 ((,,,) a b c) 
(Show a, Show b, Show c, Show d) => Show1 ((,,,,) a b c d) 
(Show a, Show b, Show c, Show d, Show e) => Show1 ((,,,,,) a b c d e) 
(Show a, Show b, Show c, Show d, Show e, Show f) => Show1 ((,,,,,,) a b c d e f) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g) => Show1 ((,,,,,,,) a b c d e f g) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h) => Show1 ((,,,,,,,,) a b c d e f g h) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i) => Show1 ((,,,,,,,,,) a b c d e f g h i) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j) => Show1 ((,,,,,,,,,,) a b c d e f g h i j) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k) => Show1 ((,,,,,,,,,,,) a b c d e f g h i j k) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l) => Show1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m) => Show1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) 
(Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n) => Show1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) 

showbUnary1 :: (Show1 f, Show a) => Builder -> Int -> f a -> Builder Source

showbUnary1 n p x produces the Builder 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

showbBinary1 n p x y produces the Builder representation of a binary data constructor with name n and arguments x and y, in precedence context p.

Since: 0.5

Builders

toString :: Builder -> String Source

Convert a Builder to a String (without surrounding it with double quotes, as show would).

Since: 0.4.1

toText :: Builder -> Text Source

Convert a Builder to a strict Text.

Since: 0.4.1

lengthB :: Builder -> Int64 Source

Computes the length of a Builder.

Since: 0.3

replicateB :: Int64 -> Builder -> Builder Source

Deprecated: Use timesN from the semigroups library instead.

replicateB n b yields a Builder containing b repeated n times.

Since: 0.3

unlinesB :: [Builder] -> Builder Source

Merges several Builders, separating them by newlines.

Since: 0.1

unwordsB :: [Builder] -> Builder Source

Merges several Builders, 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

Conversion between String and Text Show

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

Constructors

FromStringShow 

Fields

fromStringShow :: a
 

newtype FromTextShow a Source

The String Show instance for FromTextShow is based on its Text Show instance. That is,

showsPrec p (FromTextShow x) str = toString (showbPrec p x) ++ str

Since: 0.6

Constructors

FromTextShow 

Fields

fromTextShow :: a