| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Howl.Symbol
Description
The public symbol type used in Howl expressions.
Symbols are interned names such as x, Plus, or List.
By default, Howl uses the symbolize library as its symbol
implementation. There is also a simpler implementation in
Howl.Symbol.Simple based on a newtype over ShortText,
but it is currently turned off by default.
Synopsis
- data Symbol
- symbolToShortText :: Symbol -> ShortText
- symbolFromShortText :: ShortText -> Symbol
Documentation
A string-like type with O(1) equality and comparison.
A Symbol represents a string (any Textual, so String, Text, ShortText, ByteString, ShortByteString, etc.)
Just like ShortText, ShortByteString and ByteArray, a Symbol has an optimized memory representation,
directly wrapping a primitive ByteArray#.
Furthermore, a global symbol table keeps track of which values currently exist, ensuring we always deduplicate symbols.
This therefore allows us to:
- Check for equality between symbols in constant-time (using pointer equality)
- Calculate the hash in constant-time (using StableName)
- Keep the memory footprint of repeatedly-seen strings low.
This is very useful if you're frequently comparing strings
and the same strings might come up many times.
It also makes Symbol a great candidate for a key in e.g. a HashMap or HashSet.
The global symbol table is implemented using weak pointers, which means that unused symbols will be garbage collected. As such, you do not need to be concerned about memory leaks (as is the case with many other symbol table implementations).
Symbols are considered 'the same' regardless of whether they originate
from a String, (lazy or strict, normal or short) Text, (lazy or strict, normal or short) ByteString etc.
Instances
| Binary Symbol | Uses the Since: symbolize-1.0.1.0 |
| NFData Symbol | The contents inside a |
| Data Symbol | This Since: symbolize-1.0.1.0 |
Defined in Symbolize Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Symbol -> c Symbol # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Symbol # toConstr :: Symbol -> Constr # dataTypeOf :: Symbol -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Symbol) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Symbol) # gmapT :: (forall b. Data b => b -> b) -> Symbol -> Symbol # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Symbol -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Symbol -> r # gmapQ :: (forall d. Data d => d -> u) -> Symbol -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Symbol -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Symbol -> m Symbol # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Symbol -> m Symbol # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Symbol -> m Symbol # | |
| IsString Symbol | |
Defined in Symbolize Methods fromString :: String -> Symbol # | |
| Read Symbol | To be a good citizen w.r.t both
|
| Show Symbol | |
| Eq Symbol | Equality checking takes only O(1) time, and is a simple pointer-equality check. |
| Ord Symbol | Symbols are ordered by their lexicographical UTF-8 representation. Therefore, comparison takes O(n) time. |
| Hashable Symbol | Hashing a
|
| FromExpr Symbol # | |
| ToExpr Symbol # | |
Defined in Howl.Expr.Internal | |
| PPrint Symbol # | |
Defined in Howl.Symbol.Symbolize | |
symbolToShortText :: Symbol -> ShortText #
Convert a symbol to its short-text name.
symbolFromShortText :: ShortText -> Symbol #
Intern a short-text name as a symbol.