| Crates.io | bhc-intern |
| lib.rs | bhc-intern |
| version | 0.2.1 |
| created_at | 2026-01-25 17:29:27.468425+00 |
| updated_at | 2026-01-25 18:24:18.158769+00 |
| description | String interning for efficient symbol handling |
| homepage | |
| repository | https://github.com/raskell-io/bhc |
| max_upload_size | |
| id | 2069135 |
| size | 22,019 |
String interning for efficient symbol handling in the Basel Haskell Compiler.
This crate provides interned strings (symbols) that enable O(1) equality comparisons and reduced memory usage for repeated strings. A global interner ensures that each unique string is stored only once.
| Type | Description |
|---|---|
Symbol |
An interned string, cheap to copy and compare |
Ident |
An identifier with a name symbol |
kw::* |
Pre-interned keywords for common Haskell identifiers |
use bhc_intern::{Symbol, Ident, kw};
// Intern a string
let s1 = Symbol::intern("hello");
let s2 = Symbol::intern("hello");
// O(1) comparison (just compares indices)
assert_eq!(s1, s2);
// Get the string value
assert_eq!(s1.as_str(), "hello");
// Use pre-interned keywords
kw::intern_all(); // Optional: pre-intern for better performance
assert_eq!(*kw::LET, "let");
assert_eq!(*kw::WHERE, "where");
// Create identifiers
let id = Ident::from_str("myFunction");
println!("{}", id); // prints: myFunction
The kw module provides pre-interned symbols for common Haskell keywords:
Haskell Keywords: case, class, data, deriving, do, else, forall, foreign, if, import, in, infix, infixl, infixr, instance, let, module, newtype, of, qualified, then, type, where
BHC Extensions: lazy, strict, profile, edition
Common Types: Int, Float, Double, Bool, Char, String, ()
Common Constructors: True, False, Just, Nothing, Left, Right
The global interner is thread-safe using RwLock. The fast path (already interned) only requires a read lock.
Copy and very cheap to pass aroundkw::intern_all() at startup for predictable performancebhc-ast - Uses symbols for identifiers in the ASTbhc-hir - Uses symbols for names in HIRbhc-core - Uses symbols for variable names in Core IR