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

Moduleghc-9.10.3GHC2021

GHC.Data.FastString

There are two principal string types used internally by GHC:

FastString
  • A compact, hash-consed, representation of character strings.

  • Generated by fsLit.

  • You can get a Unique from them.

  • Equality test is O(1) (it uses the Unique).

  • Comparison is O(1) or O(n):

  • O(n) but deterministic with lexical comparison (lexicalCompareFS)

  • O(1) but non-deterministic with Unique comparison (uniqCompareFS)

  • Turn into SDoc with ftext.

PtrString
  • Pointer and size of a Latin-1 encoded string.

  • Practically no operations.

  • Outputting them is fast.

  • Generated by mkPtrString#.

  • Length of string literals (mkPtrString# "abc"#) is computed statically

  • Turn into SDoc with ptext

  • Requires manual memory management. Improper use may lead to memory leaks or dangling pointers.

  • It assumes Latin-1 as the encoding, therefore it cannot represent arbitrary Unicode strings.

Use PtrString unless you want the facilities of FastString.

  • 5 types
  • 36 values
  • Packageghc-9.10.3
  • Exports41
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceFastString.hs

ByteString

5 declarations

ShortByteString

2 declarations

ShortText

1 declaration

FastZString

5 declarations

FastStrings

3 declarations
datadata FastString
#

A FastString is a UTF-8 encoded string together with a unique ID. All FastStrings are stored in a global hashtable to support fast O(1) comparison.

It is also associated with a lazy reference to the Z-encoding of this string which is used by the compiler internally.

Constructors

Instances14Eq, Data, Show, IsString, Semigroup, Monoid, …
newtypenewtype NonDetFastString
#

Non-deterministic FastString

This is a simple FastString wrapper with an Ord instance using uniqCompareFS (i.e. which compares FastStrings on their Uniques). Hence it is not deterministic from one run to the other.

Instances6Eq, Data, Ord, Show, Outputable, Binary
newtypenewtype LexicalFastString
#

Lexical FastString

This is a simple FastString wrapper with an Ord instance using lexicalCompareFS (i.e. which compares FastStrings on their String representation). Hence it is deterministic from one run to the other.

Instances6Eq, Data, Ord, Show, Outputable, Binary

Construction

Deconstruction

Encoding

Operations

Outputting

Internal

PtrStrings

1 declaration

Construction

Deconstruction

Operations