The HashConsGroundFn functor
Author: John Reppy
Keywords: Standard ML, SML, SML/NJ Library

The SML of NJ Library
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.

## Synopsis

    functor HashConsGroundFn (T : HASH_KEY)

## Arguments

- `T : HASH_KEY`:: The argument structure `T` defines 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)

## See Also

`HashCons`, The HashCons Library

SML/NJ Version 110.99.9 (November 4, 2025)
Last updated 2025-11-04 15:48:25 UTC