Hasty Briefsbeta

Bilingual

Record type inference for dummies

3 days ago
  • #Type Theory
  • #Row Polymorphism
  • #Anonymous Records
  • Author introduces type inference for anonymous records to bridge knowledge gap in type theory.
  • Anonymous records are data structures without a pre-declared type, common in dynamic languages (e.g., JavaScript objects, Python dictionaries).
  • Static typing languages like Haskell require named datatypes for records, while some (TypeScript, C#, PureScript) support anonymous records.
  • Basic type inference rules are defined for literals (booleans, strings, numbers) and record literals using a formal notation.
  • Field access and variables are added to the language, requiring type inference rules that can fail (e.g., missing fields, unbound variables).
  • Functions introduce complexity; inferring types for functions like 'getName' leads to row polymorphism to handle extra fields.
  • Row polymorphism uses row variables (e.g., ρ) to abstract over sets of fields, enabling record extension and better type inference.
  • Record extension (adding/overriding fields) benefits from row polymorphism, unlike TypeScript's clumsier type handling.
  • Author's interest in row polymorphism stems from type-checking Nix's record concatenation operator (//), referencing relevant research.
  • Appendix includes complete Haskell code for the type inference system discussed.