The HashConsGroundFn functor provides a mechanism for defining
a hash-consed representations for "leaf" (or "ground") types.
These are types that might be atomic (e.g.,
the HashConsAtom structure) or
datatypes, but they are treated as atomic values by the HashCons Library
and are the leaves of the hash-consed data structures.
Synopsis
functor HashConsGroundFn (T : HASH_KEY)
Arguments
-
T : HASH_KEY:: The argument structureTdefines the type, equality function, and hashing function a the "leaf" type.
Interface
type hash_key = T.hash_key
type obj = hash_key HashCons.obj
val mk : hash_key -> obj
Description
type hash_key = T.hash_key-
the ground type.
type obj = hash_key HashCons.obj-
the hash-consed ground type.
val mk : hash_key -> obj-
map a ground type value to a hash-consed value.
Example
Suppose that we wish to have pairs of integers as a ground type for a hash-consed data structure. We might implement this using the following functor application:
structure HCPairs = HashConsGroundFn (
struct
type hash_key = int * int
fun sameKey (a : hash_key, b) = (a = b)
fun hashVal (a, b) = Word.xorb(Word.fromInt a, Word.fromInt b)
end)