Defining Type Constructors
Encode type constructors as interface lookups.
Naming Type Constructors
The encoding starts by giving each type constructor a unique string identifier called a URI. The URI is a tag that stands in for the constructor wherever we cannot pass the constructor itself.
type ArrayURI = "Array";
type OptionURI = "Option";
// Each container gets a unique string tagA Registry Interface
We keep a single interface that maps each URI to the concrete type it produces for a given argument A. This interface is the registry. Each key is a URI; each value is the resolved type.
interface URItoKind<A> {
Array: Array<A>;
Option: A | null;
}
// URItoKind<number>["Array"] is number[]All lessons in this course
- The HKT Problem in TypeScript
- Defining Type Constructors
- The Lightweight HKT Pattern
- Generic Functors and Mappers