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-2.1.3Haskell2010

Data.Text.Internal

A module containing private Text internals. This exposes the Text representation and low level construction functions. Modules which extend the Text system may need to use this module.

You should not use this module unless you are determined to monkey with the internals, as the functions here do just about nothing to preserve data invariants. You have been warned!

  • 2 types
  • 11 values
  • Packagetext-2.1.3
  • Exports13
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceInternal.hs

Types

2 declarations

Internally, the Text type is represented as an array of Word8 UTF-8 code units. The offset and length fields in the constructor are in these units, not units of Char.

Invariants that all functions must maintain:

  • Since the Text type uses UTF-8 internally, it cannot represent characters in the reserved surrogate code point range U+D800 to U+DFFF. To maintain this invariant, the safe function maps Char values in this range to the replacement character (U+FFFD, '�').

  • Offset and length must point to a valid UTF-8 sequence of bytes. Violation of this may cause memory access violation and divergence.

datadata Text
#

A space efficient, packed, unboxed Unicode text type.

Constructors

Instances14IsList, Eq, Data, Ord, Read, Show, …
  • IsList TextDefined in text-2.1.3 · Data.Text · orphan

    Performs replacement on invalid scalar values:

    Example2 expressions
    :set -XOverloadedLists['\55555'] :: Text"\65533"
  • Eq TextDefined in text-2.1.3 · Data.Text · orphan
  • Data TextDefined in text-2.1.3 · Data.Text · orphan

    This instance preserves data abstraction at the cost of inefficiency. We omit reflection services for the sake of data abstraction.

    This instance was created by copying the updated behavior of Data.Set.Set and Data.Map.Data.Map.Map. If you feel a mistake has been made, please feel free to submit improvements.

    The original discussion is archived here: could we get a Data instance for Data.Text.Text?

    The followup discussion that changed the behavior of Set and Data.Map.Map is archived here: Proposal: Allow gunfold for Data.Map, ...

  • Ord TextDefined in text-2.1.3 · Data.Text · orphan
  • Read TextDefined in text-2.1.3 · Data.Text · orphan
  • Show TextDefined in text-2.1.3 · Data.Text.Show · orphan
  • IsString TextDefined in text-2.1.3 · Data.Text · orphan

    Performs replacement on invalid scalar values:

    Example2 expressions
    :set -XOverloadedStrings"\55555" :: Text"\65533"
  • Semigroup TextDefined in text-2.1.3 · Data.Text · orphan

    Beware: stimes will crash if the given number does not fit into an Int.

  • Monoid TextDefined in text-2.1.3 · Data.Text · orphan
  • PrintfArg TextDefined in text-2.1.3 · Data.Text · orphan
  • NFData TextDefined in text-2.1.3 · Data.Text · orphan
  • Binary TextDefined in text-2.1.3 · Data.Text · orphan
  • Lift TextDefined in text-2.1.3 · Data.Text · orphan
  • type Item Text = CharDefined in text-2.1.3 · Data.Text · orphan

Construction

2 declarations
valuetext
  1. :: Array

    bytearray encoded as UTF-8

  2. -> Int

    offset in bytes (not in Char!), pointing to a start of UTF-8 sequence

  3. -> Int

    length in bytes (not in Char!), pointing to an end of UTF-8 sequence

  4. -> Text
#

Construct a Text without invisibly pinning its byte array in memory if its length has dwindled to zero. It ensures that empty Text values are shared.

Safety

1 declaration
valuesafe :: Char -> Char
#

Map a Char to a Text-safe value.

Unicode Surrogate code points are not included in the set of Unicode scalar values, but are unfortunately admitted as valid Char values by Haskell. They cannot be represented in a Text. This function remaps those code points to the Unicode replacement character (U+FFFD, '�'), and leaves other code points unchanged.

Code that must be here for accessibility

2 declarations

Utilities

1 declaration
valuefirstf :: (a -> c) -> Maybe (a, b) -> Maybe (c, b)
#

Apply a function to the first element of an optional pair.

Checked multiplication

3 declarations
valuemul :: Int -> Int -> Int
#

Checked multiplication. Calls error if the result would overflow.

Debugging

1 declaration

Conversions

1 declaration
valuepack :: String -> Text
#

O(n) Convert a String into a Text. Performs replacement on invalid scalar values, so unpack . pack is not id:

Example1 expression
Data.Text.unpack (pack "\55555")"\65533"