HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduletext-builder-linear-0.1.2GHC2021

Data.Text.Builder.Linear

Builder for strict Text and ByteString, based on linear types. It consistently outperforms Data.Text.Lazy.Builder from text as well as a strict builder from text-builder, and scales better.

  • 1 type
  • 8 values
newtypenewtype Builder
#

Thin wrapper over Buffer with a handy Semigroup instance.

Example2 expressions
:set -XOverloadedStrings -XMagicHashfromText "foo" <> fromChar '_' <> fromAddr "bar"#"foo_bar"

Remember: this is a strict builder, so on contrary to Data.Text.Lazy.Builder for optimal performance you should use strict left folds instead of lazy right ones.

Note that (similar to other builders) concatenation of Builders allocates thunks. This is to a certain extent mitigated by aggressive inlining, but it is faster to use Buffer directly.

Constructors

Instances4Show, IsString, Semigroup, Monoid
  • Show BuilderDefined in text-builder-linear-0.1.2 · Data.Text.Builder.Linear
  • IsString BuilderDefined in text-builder-linear-0.1.2 · Data.Text.Builder.Linear
  • Semigroup BuilderDefined in text-builder-linear-0.1.2 · Data.Text.Builder.Linear
  • Monoid BuilderDefined in text-builder-linear-0.1.2 · Data.Text.Builder.Linear
valuerunBuilder :: Builder %m -> Text
#

Run Builder computation on an empty Buffer, returning strict Text.

Example2 expressions
:set -XOverloadedStrings -XMagicHashrunBuilder (fromText "foo" <> fromChar '_' <> fromAddr "bar"#)"foo_bar"

This function has a polymorphic arrow and thus can be used both in usual and linear contexts.

valuefromText :: Text -> Builder
#

Create Builder, containing a given Text.

Example2 expressions
:set -XOverloadedStringsfromText "foo" <> fromText "bar""foobar"
valuefromChar :: Char -> Builder
#

Create Builder, containing a given Char.

Example1 expression
fromChar 'x' <> fromChar 'y'"xy"

In contrast to singleton, it's a responsibility of the caller to sanitize surrogate code points with safe.

valuefromAddr :: Addr# -> Builder
#

Create Builder, containing a null-terminated UTF-8 string, specified by Addr#.

Example2 expressions
:set -XMagicHashfromAddr "foo"# <> fromAddr "bar"#"foobar"

The literal string must not contain zero bytes \0 and must be a valid UTF-8, these conditions are not checked.

valuefromHex :: (Integral a, FiniteBits a) => a -> Builder
#

Create Builder, containing hexadecimal representation of a given integer.

Example2 expressions
:set -XMagicHashfromAddr "0x"# <> fromHex (0x123def :: Int)"0x123def"
valuefromDouble :: Double -> Builder
#

Create Builder, containing decimal representation of a given Double.

Example2 expressions
:set -XMagicHashfromAddr "pi="# <> fromDouble pi"pi=3.141592653589793"