HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

datadata TextBuilder

Composable specification of how to efficiently construct strict Text.

Provides instances of Semigroup and Monoid, which have complexity of O(1).

Instances6Eq, Show, IsString, Semigroup, Monoid, Arbitrary

Accessors

Constructors

Transformations

Run the builder and pack the produced text into a new builder.

Useful to have around builders that you reuse, because a forced builder is much faster, since it's virtually a single call to memcopy.

Textual

UTF-8 bytestring. You can use it for converting ASCII values as well.

Warning: It's your responsibility to ensure that the bytestring is properly encoded.

Example1 expression
unsafeUtf8ByteString "abc""abc"
Example2 expressions
import Data.Text.Encoding (encodeUtf8)unsafeUtf8ByteString (encodeUtf8 "фывапролдж") == "фывапролдж"True

Character

Integers

Decimal

valuedecimal :: Integral a => a -> TextBuilder

Signed decimal representation of an integer.

Example1 expression
decimal 123456"123456"
Example1 expression
decimal (-123456)"-123456"
Example1 expression
decimal 0"0"
Example1 expression
decimal (-2 :: Int8)"-2"
Example1 expression
decimal (-128 :: Int8)"-128"

Fixed-length decimal without sign. Padded with zeros or trimmed depending on whether it's shorter or longer than specified.

Example1 expression
fixedLengthDecimal 5 123"00123"
Example1 expression
fixedLengthDecimal 5 123456"23456"
Example1 expression
fixedLengthDecimal 5 (-123456)"23456"
Example1 expression
fixedLengthDecimal 7 (-123456)"0123456"
Example1 expression
fixedLengthDecimal 0 123""
Example1 expression
fixedLengthDecimal (-2) 123""

Decimal representation of an integral value with thousands separated by the specified character.

Example1 expression
thousandSeparatedDecimal ',' 1234567890"1,234,567,890"
Example1 expression
thousandSeparatedDecimal ' ' (-1234567890)"-1 234 567 890"

Binary

valuebinary :: FiniteBits a => a -> TextBuilder

Two's complement binary representation of a value.

Bits of a statically sized value padded from the left according to the size. If it's a negatable integer, the sign is reflected in the bits.

Example1 expression
binary @Int8 0"00000000"
Example1 expression
binary @Int8 4"00000100"
Example1 expression
binary @Int8 (-1)"11111111"
Example1 expression
binary @Word8 255"11111111"
Example1 expression
binary @Int16 4"0000000000000100"
Example1 expression
binary @Int16 (-4)"1111111111111100"

Octal

valueoctal :: (FiniteBits a, Integral a) => a -> TextBuilder

Octal representation of an integer.

Example1 expression
octal @Int32 123456"00000361100"
Example1 expression
octal @Int32 (-123456)"77777416700"

Hexadecimal

Integer in hexadecimal notation with a fixed number of digits determined by the size of the type.

Example1 expression
hexadecimal @Int8 0"00"
Example1 expression
hexadecimal @Int8 4"04"
Example1 expression
hexadecimal @Int8 (-128)"80"
Example1 expression
hexadecimal @Int8 (-1)"ff"
Example1 expression
hexadecimal @Word8 255"ff"
Example1 expression
hexadecimal @Int32 123456"0001e240"
Example1 expression
hexadecimal @Int32 (-123456)"fffe1dc0"