On the State of Coherence in the Land of Type Classes

Type classes are a popular tool for implementing generic algorithms and data structures without loss of efficiency, bridging the gap between parametric and ad-hoc polymorphism.Since their initial development in Haskell, they now feature prominently in numerous other industry-ready programming languages, notably including Swift, Rust, and Scala.The success of type classes hinges in large part on the compilers' ability to infer arguments to implicit parameters by means of a type-directed resolution.This technique, sometimes dubbed implicit programming, lets users elide information that the language implementation can deduce from the context, such as the implementation of a particular type class.One drawback of implicit programming is that a type-directed resolution may yield ambiguous results, thereby threatening coherence, the property that valid programs have exactly one meaning.This issue has divided the community on the right approach to address it.One side advocates for flexibility where implicit resolution is context-sensitive and often relies on dependent typing features to uphold soundness.The other holds that context should not stand in the way of equational reasoning and typically imposes that type class instances be unique across the entire program to fend off ambiguities.Although there exists a large body of work on type classes and implicit programming, most of the scholarly literature focuses on a few select languages and offers little insight into other mainstream projects.Meanwhile, the latter have evolved similar features and/or restrictions under different names, making it difficult for language users and designers to get a sense of the full design space.To alleviate this issue, we set to examine Swift, Rust, and Scala, three popular languages featuring type classes heavily, and relate their approach to coherence to Haskell's.It turns out that, beyond superficial syntactic differences, Swift, Rust, and Haskell are actually strikingly similar in that the three languages offer comparable strategies to work around the limitations of the uniqueness of type class instances.

Authors

Institutions

Publication Details

Journal
The Art Science and Engineering of Programming
Published
2025-02-15
DOI
https://doi.org/10.22152/programming-journal.org/2026/10/15
Primary Topic
Political Economy and Marxism
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

On the State of Coherence in the Land of Type Classes

Dimitri Racordon, Eugene Flesselle, Cao Nguyen Pham
The Art Science and Engineering of Programming
Political Economy and Marxism
article

On the State of Coherence in the Land of Type Classes

Dimitri Racordon, Eugene Flesselle, Cao Nguyen Pham
article en

Abstract

Type classes are a popular tool for implementing generic algorithms and data structures without loss of efficiency, bridging the gap between parametric and ad-hoc polymorphism.Since their initial development in Haskell, they now feature prominently in numerous other industry-ready programming languages, notably including Swift, Rust, and Scala.The success of type classes hinges in large part on the compilers' ability to infer arguments to implicit parameters by means of a type-directed resolution.This technique, sometimes dubbed implicit programming, lets users elide information that the language implementation can deduce from the context, such as the implementation of a particular type class.One drawback of implicit programming is that a type-directed resolution may yield ambiguous results, thereby threatening coherence, the property that valid programs have exactly one meaning.This issue has divided the community on the right approach to address it.One side advocates for flexibility where implicit resolution is context-sensitive and often relies on dependent typing features to uphold soundness.The other holds that context should not stand in the way of equational reasoning and typically imposes that type class instances be unique across the entire program to fend off ambiguities.Although there exists a large body of work on type classes and implicit programming, most of the scholarly literature focuses on a few select languages and offers little insight into other mainstream projects.Meanwhile, the latter have evolved similar features and/or restrictions under different names, making it difficult for language users and designers to get a sense of the full design space.To alleviate this issue, we set to examine Swift, Rust, and Scala, three popular languages featuring type classes heavily, and relate their approach to coherence to Haskell's.It turns out that, beyond superficial syntactic differences, Swift, Rust, and Haskell are actually strikingly similar in that the three languages offer comparable strategies to work around the limitations of the uniqueness of type class instances.

The Art Science and Engineering of ProgrammingVol. 10(1)
École Polytechnique Fédérale de Lausanne (CH)
Openalex Percentile: Top 95%
Political Economy and Marxism
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.