HORIZON HASKELLDocslts/ghc-10.0.xfc4e5982026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Moduletext-builder-1.0.0.5Haskell2010

TextBuilder

  • 1 type
  • 21 values
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

3 declarations

Constructors

0 declarations

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

Safe Unicode codepoint with invalid values replaced by the � char (codepoint 0xfffd), which is the same as what Data.Text.pack does.

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"
valuefixedLengthDecimal :: Integral a => Int -> a -> TextBuilder
#

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

valuehexadecimal :: (FiniteBits a, Integral a) => a -> TextBuilder
#

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"