The HashConsGroundFn functor

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.


functor HashConsGroundFn (T : HASH_KEY)


  • T : HASH_KEY:: The argument structure T defines the type, equality function, and hashing function a the "leaf" type.


type hash_key = T.hash_key
type obj = hash_key HashCons.obj

val mk : hash_key -> obj


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.


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 (
      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)