Legend:
Library
Module
Module type
Parameter
Class
Class type
Extensible runtime type indicators and equality constraints.
Overview
This module provides logic for encapsulating arbitrary OCaml values with a runtime type indication, here called a type nym. A function is provided to compose a value and its corresponding type nym into a value of opaque type. Additional functions are provided to extract a typed value from an opaque value when provided with a nym for an equivalent type.
To handle the case where the nym type is extended, a class is provided that tests for equivalence of two nyms. Extending the nym type entails defining an subclass with methods that test for equivalence of the new variant cases. The functions that extract from values of opaque type are declared in a module signature that can be instantiated from an instance of the equivalence class.
The type nym indicating a value of opaque type. This kind of recursion is often useful for representing containers of heterogenously typed values that may themselves include containers.
A class that defines the equality constraint for all the type nyms defined above and provides for extending the equality constraint for new type nyms by defining subclasses.
The signature of modules for extracting opaque values within a given type equivalence horizon. Because all the functions in this module use the equiv method on the horizon used to construct it, expressions that directly match on the `Witness (_, nym)` type constructor are likely to be substantially more efficient.
Use eq a b to produce the equivalence constraint for the types associated with nyms a and b under the horizon. Returns Eq if a and b are nyms for equivalent types, otherwise raises Type_error.