A deep dive into a bug in the Grace programming language caused by a flawed heuristic for inferring list element types in a bidirectional typechecking system. The author explains how Grace's typechecker inferred the type of a list by using only the first element's type, causing subsequent elements to be coerced and fields stripped. The fix introduces a 'most-specific supertype' (least upper bound) computation over all element types, enabling correct type inference for heterogeneous record lists — a key requirement for ergonomic JSON interop. The post also explains why record coercion is necessary for soundness when supporting optional field access on real-world JSON data.

12m read timeFrom haskellforall.com
Post cover image
Table of contents
The problemBidirectional typecheckingElaborationThe solutionConclusionAppendix: record coercion

Sort: