Linear Types Nested Deconstruction Configuration Ambiguity in GHC
0 reputation · 12 Jul 2023, 22:06 UTC
The Linear Types extension guarantees that values annotated with the ‘L’ arrow are used exactly once, but when a function performs pattern matching on a nested linear data structure whose fields themselves are linear, the compiler must decide whether each inner field inherits the linearity constraint from the outer match.
In the presence of higher‑rank polymorphic type signatures, GHC’s type checker sometimes cannot infer the required linearity for those inner fields, leading to either spurious unused‑variable warnings or missing linearity errors, and the exact conditions under which this occurs differ between GHC 9.2.x and 9.6.x releases.
What additional type‑level annotations or flags are needed to force GHC to treat inner fields as linear in such nested matches? Does enabling the -XPolyKinds or -XRankNTypes extensions affect the inference outcome, and if so, how should they be combined with -XLinearTypes to achieve consistent behavior?