Symbol is:module

Utilities for working with KnownSymbol constraints.

Symbols

Type-level strings. Note that the operators from this module conflict with GHC.TypeLits. Symbol also has instances of (<>) and MEmpty.
This defines a datatype for representing identifiers that can be used with Crucible. These must start with an ASCII letter and can consist of any characters in the set [a-z A-Z '0-9' '_'] as long as the result is not an SMTLIB or Yices keyword.
JS symbol generation
Handling symbolic link using Win32 API. [Vista of later and desktop app only] Note: When using the createSymbolicLink* functions without the SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag, you should worry about UAC (User Account Control) when use this module's function in your application:
  • require to use 'Run As Administrator' to run your application.
  • or modify your application's manifest file to add <requestedExecutionLevel level=requireAdministrator uiAccess=false/>.
Starting from Windows 10 version 1703 (Creators Update), after enabling Developer Mode, users can create symbolic links without requiring the Administrator privilege in the current process. Supply a True flag in addition to the target and link name to enable this behavior.
Handling symbolic link using Win32 API. [Vista of later and desktop app only] Note: When using the createSymbolicLink* functions without the SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag, you should worry about UAC (User Account Control) when use this module's function in your application:
  • require to use 'Run As Administrator' to run your application.
  • or modify your application's manifect file to add <requestedExecutionLevel level=requireAdministrator uiAccess=false/>.
Starting from Windows 10 version 1703 (Creators Update), after enabling Developer Mode, users can create symbolic links without requiring the Administrator privilege in the current process. Supply a True flag in addition to the target and link name to enable this behavior.
GtkSymbolicPaintable is an interface that support symbolic colors in paintables. GdkPaintables implementing the interface will have the SymbolicPaintable.snapshot_symbolic() function called and have the colors for drawing symbolic icons passed. At least 4 colors are guaranteed to be passed every time. These 4 colors are the foreground color, and the colors to use for errors, warnings and success information in that order. More colors may be added in the future. Since: 4.6
This defines a type family SymbolRepr for representing a type-level string (AKA symbol) at runtime. This can be used to branch on a type-level value. The TestEquality and OrdF instances for SymbolRepr are implemented using unsafeCoerce. This should be typesafe because we maintain the invariant that the string value contained in a SymbolRepr value matches its static type. At the type level, symbols have very few operations, so SymbolRepr correspondingly has very few functions that manipulate them.
A demonstration of the use of the SymbolicT and QueryT transformers in the setting of symbolic program evaluation. In this example, we perform symbolic evaluation across three steps:
  1. allocate free variables, so we can extract a model after evaluation
  2. perform symbolic evaluation of a program and an associated property
  3. querying the solver for whether it's possible to find a set of program inputs that falsify the property. if there is, we extract a model.
To simplify the example, our programs always have exactly two integer inputs named x and y.
Symbolic number, i.e., these are not numbers at all, but just build a representation of the expressions. This implementation is incomplete in that it allows comnstruction, but not deconstruction of the expressions. It's mainly useful for debugging.
An interface that supports symbolic colors in paintables. GdkPaintables implementing the interface will have the SymbolicPaintable.snapshot_symbolic() function called and have the colors for drawing symbolic icons passed. At least 4 colors are guaranteed to be passed every time. These 4 colors are the foreground color, and the colors to use for errors, warnings and success information in that order. More colors may be added in the future. Since: 4.6
This module contains the definition of Symbol, SymbolMap, and helper functions for working with them. SymbolMap is one of the representations of input data.
Implementation of a global Symbol Table, with garbage collection. Symbols, also known as Atoms or Interned Strings, are a common technique to reduce memory usage and improve performance when using many small strings: 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. The main advantages of Symbolize over other symbol table implementations are:
  • Garbage collection: Symbols which are no longer used are automatically cleaned up.
  • Support for any Textual type, including String, (strict and lazy) Text, (strict and lazy) ByteString, ShortText, ShortByteString, etc.
  • Great memory usage:
  • Symbols are simply a (lifted) wrapper around a ByteArray#, which is nicely unpacked by GHC.
  • The symbol table is an IntMap that contains weak pointers to these same ByteArray#s and their associated StableName#s
  • Great performance:
  • unintern is a simple pointer-dereference
  • calls to lookup are free of atomic memory barriers (and never have to wait on a concurrent thread running intern)
  • Thread-safe

Basic usage

This module is intended to be imported qualified, e.g.
import Symbolize (Symbol)
import qualified Symbolize
To intern a string, use intern:
>>> hello = Symbolize.intern "hello"

>>> world = Symbolize.intern "world"

>>> (hello, world)
(Symbolize.intern "hello",Symbolize.intern "world")
Interning supports any Textual type, so you can also use Text or ByteString etc.:
>>> import Data.Text (Text)

>>> niceCheeses = fmap Symbolize.intern (["Roquefort", "Camembert", "Brie"] :: [Text])

>>> niceCheeses
[Symbolize.intern "Roquefort",Symbolize.intern "Camembert",Symbolize.intern "Brie"]
And if you are using OverloadedStrings, you can use the IsString instance to intern constants:
>>> hello2 = ("hello" :: Symbol)

>>> hello2
Symbolize.intern "hello"

>>> Symbolize.intern ("world" :: Text)
Symbolize.intern "world"
Comparisons between symbols run in O(1) time:
>>> hello == hello2
True

>>> hello == world
False
To get back the textual value of a symbol, use unintern:
>>> Symbolize.unintern hello
"hello"
If you want to check whether a string is currently interned, use lookup:
>>> Symbolize.lookup "hello"
Just (Symbolize.intern "hello")
Symbols make great keys for HashMap and HashSet. Hashing them takes constant-time and they are guaranteed to be unique:
>>> Data.Hashable.hash hello
1

>>> Data.Hashable.hash world
2

>>> fmap Data.Hashable.hash niceCheeses
[3,4,5]
For introspection, you can look at how many symbols currently exist:
>>> System.Mem.performGC

>>> Symbolize.globalSymbolTableSize
5

>>> [unintern (intern (show x)) | x <- [1..5]]
["1","2","3","4","5"]

>>> Symbolize.globalSymbolTableSize
10
Unused symbols will be garbage-collected, so you don't have to worry about memory leaks:
>>> System.Mem.performGC

>>> Symbolize.globalSymbolTableSize
5
For deeper introspection, you can look at the Show instance of the global symbol table: (Note that the exact format is subject to change.)
>>> Symbolize.globalSymbolTable
GlobalSymbolTable { size = 5, symbols = ["Brie","Camembert","Roquefort","hello","world"] }
Symmetry operations generater of Hall Symbols
  • References
  1. Concise Space-Group Symbols http://cci.lbl.gov/sginfo/hall_symbols.html , See also : https://github.com/rwgk/sginfo
  2. Space-Group Notation with an Explicit Origin S.R. Hall; Space-Group Notation with an Explicit Origin ; Acta Cryst. (1981). A37, 517-525
  3. ITVB 2001 Table A1.4.2.7 Hall symbols http://cci.lbl.gov/sginfo/itvb_2001_table_a1427_hall_symbols.html
Spacegroup Symbols
  • References
  1. Concise Space-Group Symbols http://cci.lbl.gov/sginfo/hall_symbols.html , See also : https://github.com/rwgk/sginfo
  2. ITVB 2001 Table A1.4.2.7 Hall symbols http://cci.lbl.gov/sginfo/itvb_2001_table_a1427_hall_symbols.html