BSD-3-Clause licensed and maintained by Geoffrey Mainland
This version can be pinned in stack with:symbol-0.3.0@sha256:ee2a80996e041b11b229edbd2fd5f7fd42f5e6288e637fd485b79de8aa143e24,1876

Module documentation for 0.3.0

The symbol Package Hackage Actions Status: haskell-ci

Provides a Symbol data type allowing fast symbol comparisons and functions for interning symbols and recovering their String representation.

import Data.Symbol (intern, unintern)

intern "name" == intern "name"  -- True
unintern (intern "name")        -- "name"

Symbols created through intern compare equal exactly when their strings do. Equality and ordering compare integer identifiers in constant time. Ordering follows identifier allocation, rather than lexicographic string order, and can vary with evaluation order and between runs. For lexicographic ordering, compare the strings returned by unintern.

Interning uses a synchronized, process-wide table. Every distinct interned string and its symbol remain in that table for the lifetime of the process, even after the caller drops all references. Memory use therefore grows with the number and total size of distinct strings interned. intern fully evaluates its input string before accessing the table. Inputs must be finite and fully defined.

The Data instance exposes a Symbol constructor with one String field. Generic construction and transformations call intern, preserving symbol identity. Use Data.Symbol for the abstract API. Data.Symbol.Unsafe exposes the raw constructor, which can break the association between identifiers and strings.

To build and run the test suite:

cabal build all
cabal test all --test-show-details=direct

The package supports GHC 8.0 and later. CI tests the versions listed in symbol.cabal; regenerate the workflow with haskell-ci regenerate after changing that list or the package components.

Formatting uses .stylish-haskell.yaml. With the VS Code Haskell extension and a working Haskell Language Server, the workspace settings enable formatting on save. To format from the command line:

stylish-haskell -i Setup.hs src/Data/Symbol.hs src/Data/Symbol/Unsafe.hs tests/Main.hs

Changes

Changelog

0.3.0

  • Add GHC 9.12 and 9.14 to CI and allow containers 0.8.
  • Fix generic Data operations to reconstruct symbols through intern, preserving the association between identifiers and strings. Compatibility change: the generic representation now has one String field instead of Int and String fields. Consumers of the old representation must adapt.
  • Require base >= 4.9, matching the GHC 8.0+ CI matrix, and remove obsolete compiler compatibility code.
  • Add baseline and regression tests, with test execution in CI.
  • Move library sources into src/, enable library warnings, and configure Stylish Haskell and VS Code formatting.
  • Document ordering, interned-string lifetime, and the generic representation.