The Lightweight HKT Pattern
Implement the Kind/URI defunctionalization trick.
Defunctionalization
The trick behind the encoding has a name: defunctionalization. Instead of a real higher-order type function, we represent each function by a tag and resolve it with a single first-order lookup. The URItoKind registry is that lookup table.
type Kind<F extends URIS, A> = URItoKind<A>[F];
// One lookup replaces true type-function applicationThe Kind Type
Kind<F, A> is the public face of the pattern. Read it as "the constructor F applied to A". It hides the registry indexing behind a clean name.
type A = Kind<"Array", number>; // number[]
type B = Kind<"Option", string>; // string | nullAll lessons in this course
- The HKT Problem in TypeScript
- Defining Type Constructors
- The Lightweight HKT Pattern
- Generic Functors and Mappers