Reference. Polymorphism with Typed Holes

Adam Chen, Thomas Porter, Cyrus Omar · · live-programming · DOI

Cite

Cite as @chen-2025-polymorphism (helia, typst) · \cite{chen-2025-polymorphism} (LaTeX)
BibTeX
bibtex · 1 line
@inbook{chen-2025-polymorphism, title={Polymorphism with Typed Holes}, ISBN={9783031745584}, ISSN={1611-3349}, url={http://dx.doi.org/10.1007/978-3-031-74558-4_7}, DOI={10.1007/978-3-031-74558-4_7}, booktitle={Trends in Functional Programming}, publisher={Springer Nature Switzerland}, author={Chen, Adam and Porter, Thomas and Omar, Cyrus}, year={2025}, pages={134–159} }
hayagriva YAML (typst)
yaml · 18 lines
chen-2025-polymorphism:
  type: chapter
  title: Polymorphism with Typed Holes
  author:
  - Chen, Adam
  - Porter, Thomas
  - Omar, Cyrus
  date: 2025
  page-range: 134-159
  url: http://dx.doi.org/10.1007/978-3-031-74558-4_7
  serial-number:
    doi: 10.1007/978-3-031-74558-4_7
    isbn: '9783031745584'
    issn: 1611-3349
  parent:
    type: book
    title: Trends in Functional Programming
    publisher: Springer Nature Switzerland
Cites 28 works (7 here)
With notes (7)

Total Type Error Localization and Recovery with Holes zhao-2024-total

Type systems typically only define the conditions under which an expression is well-typed, leaving ill-typed expressions formally meaningless. This approach is insufficient as the basis for language servers driving modern programming environments, which are expected to recover from simultaneously localized errors and continue to provide a variety of downstream semantic services. This paper addresses this problem, contributing the first comprehensive formal account of total type error localization and recovery: the marked lambda calculus. In particular, we define a gradual type system for expressions with marked errors, which operate as non-empty holes, together with a total procedure for marking arbitrary unmarked expressions. We mechanize the metatheory of the marked lambda calculus in Agda and implement it, scaled up, as the new basis for Hazel, a full-scale live functional programming environment with, uniquely, no meaningless editor states. The marked lambda calculus is bidirectionally typed, so localization decisions are systematically predictable based on a local flow of typing information. Constraint-based type inference can bring more distant information to bear in discovering inconsistencies but this notoriously complicates error localization. We approach this problem by deploying constraint solving as a type-hole-filling layer atop this gradual bidirectionally typed core. Errors arising from inconsistent unification constraints are localized exclusively to type and expression holes, i.e., the system identifies unfillable holes using a system of traced provenances, rather than localized in an ad hoc manner to particular expressions. The user can then interactively shift these errors to particular downstream expressions by selecting from suggested partially consistent type hole fillings, which returns control back to the bidirectional system. We implement this type hole inference system in Hazel.
PDF · DOI · pldb

Gradual Structure Editing with Obligations moon-2023-gradual

DOI

Bidirectional Typing dunfield-2021-bidirectional

Bidirectional typing combines two modes of typing: type checking, which checks that a program satisfies a known type, and type synthesis, which determines a type from the program. Using checking enables bidirectional typing to support features for which inference is undecidable; using synthesis enables bidirectional typing to avoid the large annotation burden of explicitly typed languages. In addition, bidirectional typing improves error locality. We highlight the design principles that underlie bidirectional type systems, survey the development of bidirectional typing from the prehistoric period before Pierce and Turner’s local type inference to the present day, and provide guidance for future investigations.
DOI · arXiv

Graduality and Parametricity: Together Again for the First Time new_jamner_ahmed_2020

Parametric polymorphism and gradual typing have proven to be a difficult combination, with no language yet produced that satisfies the fundamental theorems of each: parametricity and graduality. Notably, Toro, Labrada, and Tanter (POPL 2019) conjecture that for any gradual extension of System F that uses dynamic type generation, graduality and parametricity are “simply incompatible”. However, we argue that it is not graduality and parametricity that are incompatible per se, but instead that combining the syntax of System F with dynamic type generation as in previous work necessitates type-directed computation, which we show has been a common source of graduality and parametricity violations in previous work.

We then show that by modifying the syntax of universal and existential types to make the type name generation explicit, we remove the need for type-directed computation, and get a language that satisfies both graduality and parametricity theorems. The language has a simple runtime semantics, which can be explained by translation to a statically typed language where the dynamic type is interpreted as a dynamically extensible sum type. Far from being in conflict, we show that the parametricity theorem follows as a direct corollary of a relational interpretation of the graduality property.

PDF · DOI · pldb

Live functional programming with typed holes omar-2019-live

Live programming environments aim to provide programmers (and sometimes audiences) with continuous feedback about a program’s dynamic behavior as it is being edited. The problem is that programming languages typically assign dynamic meaning only to programs that are complete, i.e. syntactically well-formed and free of type errors. Consequently, live feedback presented to the programmer exhibits temporal or perceptive gaps. This paper confronts this “gap problem” from type-theoretic first principles by developing a dynamic semantics for incomplete functional programs, starting from the static semantics for incomplete functional programs developed in recent work on Hazelnut. We model incomplete functional programs as expressions with holes, with empty holes standing for missing expressions or types, and non-empty holes operating as membranes around static and dynamic type inconsistencies. Rather than aborting when evaluation encounters any of these holes as in some existing systems, evaluation proceeds around holes, tracking the closure around each hole instance as it flows through the remainder of the program. Editor services can use the information in these hole closures to help the programmer develop and confirm their mental model of the behavior of the complete portions of the program as they decide how to fill the remaining holes. Hole closures also enable a fill-and-resume operation that avoids the need to restart evaluation after edits that amount to hole filling. Formally, the semantics borrows machinery from both gradual type theory (which supplies the basis for handling unfilled type holes) and contextual modal type theory (which supplies a logical basis for hole closures), combining these and developing additional machinery necessary to continue evaluation past holes while maintaining type safety. We have mechanized the metatheory of the core calculus, called Hazelnut Live, using the Agda proof assistant. We have also implemented these ideas into the Hazel programming environment. The implementation inserts holes automatically, following the Hazelnut edit action calculus, to guarantee that every editor state has some (possibly incomplete) type. Taken together with this paper’s type safety property, the result is a proof-of-concept live programming environment where rich dynamic feedback is truly available without gaps, i.e. for every reachable editor state.
PDF · DOI · arXiv · pldb

Hazelnut: a bidirectionally typed structure editor calculus omar-2017-hazelnut

PDF · DOI · arXiv · pldb

Complete and easy bidirectional typechecking for higher-rank polymorphism dunfield-2013-complete

PDF · DOI · arXiv · pldb
chen-2025-polymorphism reference entries/refs/chen-2025-polymorphism/chen-2025-polymorphism.hel