Skip to main content

Type-level list algebra

The per-field state markers and list operations the extensible-data families are built from.

Overview​

These are the least user-facing traits in the reference of Context-Generic Programming (CGP), which builds and reads Rust structs and enums generically by their field and variant names. They are the type-level layer beneath the builders, extractors, and casts: the markers that record what state one field is in, and the operations that grow and reshape a type's field list. You meet them in an error message from code that walks a shape far more often than in code you wrote, and this group exists so that such a message is legible. None is in the prelude.

The group divides into the state markers and the list operations.

The state markers name how one field of a partial type is stored. MapType is the marker trait, and its IsPresent, IsNothing, and IsVoid markers are what a builder or extractor error prints. MapTypeRef does the same for a borrowed view, adding a lifetime. TransformMap carries the function that converts one field between markers, and TransformMapFields lifts that conversion across a whole record.

The list operations compute new field lists from old ones. AppendProduct adds one entry to a product and ConcatProduct splices two together, while MapFields rewrites every entry of a product or a sum through one marker.

The ideas behind them​


An AI agent wrote this page using the CGP knowledge base. Its content was verified against the library's source. See How AI is used in this project.