Labeled Tuples (Informed Position)
summary
Adds labels to tuple fields, implemented as an optional label on every field and landed in Jane Street’s OCaml branch, with a small compiler change (no row polymorphism). Patterns support partial extraction and reordering only when the compiler knows the tuple type. Labels incur no runtime cost unlike polymorphic-variant or object hacks. Duplicate and omitted labels are allowed; projection is not added yet. The feature proves popular and is used in thousands of files across the codebase.
AI-written summary · about
chapters (21)
- 0:00Introduction
- 1:19Labeled tuples in OCaml
- 2:42Label syntax and types
- 3:24Partial pattern matching
- 4:26Optional and repeated labels
- 5:49Adding label tuples
- 7:12Code without label tuples
- 9:16Alternatives to labels
- 11:21Design and implementation
- 13:24Popularity of labels
- 14:06Comparison with SML Flex records
- 15:29Labels vs records
- 16:12History of Flex records
- 17:15Future extensions
- 19:10Q&A: Design and optional params
- 20:13Q&A: Recursive types
- 20:54Q&A: Repeated labels issue
- 21:37Q&A: Scala’s similar feature
- 22:22Q&A: No Labels flag
- 22:44Q&A: Pattern matching order
- 23:48Q&A: Runtime efficiency
