Skip to main content
QUICK REVIEW

[Paper Review] Kind Inference for Datatypes: Technical Supplement

Ningning Xie, Richard A. Eisenberg|arXiv (Cornell University)|Nov 11, 2019
Logic, programming, and type systemsComputer Science50 references4 citations
TL;DR

This technical supplement formalizes kind inference for Haskell datatypes with advanced features like visible dependent quantification, datatype promotion, and partial type signatures. It presents a principled type system with formal typing rules, substitution semantics, and proofs of key properties such as principality and type safety, enabling sound and extensible kind inference in the presence of complex type-level constructs in GHC-style systems.

ABSTRACT

In recent years, languages like Haskell have seen a dramatic surge of new features that significantly extends the expressive power of their type systems. With these features, the challenge of kind inference for datatype declarations has presented itself and become a worthy research problem on its own. This paper studies kind inference for datatypes. Inspired by previous research on type-inference, we offer declarative specifications for what datatype declarations should be accepted, both for Haskell98 and for a more advanced system we call PolyKinds, based on the extensions in modern Haskell, including a limited form of dependent types. We believe these formulations to be novel and without precedent, even for Haskell98. These specifications are complemented with implementable algorithmic versions. We study soundness, completeness and the existence of principal kinds in these systems, proving the properties where they hold. This work can serve as a guide both to language designers who wish to formalize their datatype declarations and also to implementors keen to have principled inference of principal types. This technical supplement to Kind Inference for Datatypes serves to expand upon the text in the main paper. It contains detailed typing rules, proofs, and connections to the Glasgow Haskell Compiler (GHC).

Motivation & Objective

  • To formally specify kind inference for Haskell datatypes with advanced type-level features such as visible dependent quantification (VDQ), datatype promotion, and partial type signatures.
  • To extend the typing judgment and dependency analysis to handle data constructors in types and kind-level dependencies.
  • To prove key metatheoretic properties—such as principality and type safety—of the kind inference system within a formal calculus.
  • To bridge the gap between theoretical kind inference and practical implementation in GHC, ensuring correctness and extensibility.

Proposed method

  • Introduces a formal type system with a typing judgment for kind inference, extending core rules to handle polymorphic and dependent kinds.
  • Defines a substitution-based semantics using a context Θ to track kind variable instantiations and dependencies.
  • Extends the dependency analysis to include data constructor usage in types, ensuring correct kind inference even when constructors appear in type-level expressions.
  • Supports visible dependent quantification by requiring explicit kind annotations for dependent type variables, avoiding ambiguity in inference.
  • Uses a constraint-based approach for delayed solving, allowing integration with GHC’s existing constraint-solving architecture.
  • Proves principality of kind inference through structural induction and substitution lemmas, ensuring unique and deterministic kind assignment.

Experimental results

Research questions

  • RQ1How can kind inference be soundly extended to support visible dependent quantification in datatype declarations?
  • RQ2What modifications to the typing and dependency analysis rules are needed to support using data constructors as type-level values?
  • RQ3How can partial type signatures with kind annotations be integrated into the kind inference process without breaking polymorphic recursion?
  • RQ4What formal guarantees—such as principality and type safety—can be proven for a kind inference system supporting these advanced features?
  • RQ5How does the proposed system integrate with GHC’s existing constraint-based type inference architecture?

Key findings

  • The system correctly infers kinds for datatypes with visible dependent quantification, ensuring that dependent variables are explicitly declared and scoped.
  • The addition of data constructors in types is supported through an extended dependency analysis that tracks constructor-level dependencies.
  • Partial type signatures with kind annotations are handled via a modified typing rule that brings kind variables into scope, preserving type safety.
  • The system proves principality of kind inference: if a kind is derivable, it is the unique most general kind.
  • The formal system is compatible with GHC’s constraint-based inference, enabling delayed constraint solving while maintaining correctness and type safety.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.