Coherence in Type Classes: A Comparison of Swift, Rust, Scala, and Haskell
2025-03-12
Type classes are a popular mechanism for generic programming, used in languages like Haskell, Swift, Rust, and Scala. However, implicit programming, while convenient, can lead to ambiguity in type inference, jeopardizing coherence (the property that a program has exactly one meaning). The research community is divided: some favor context-sensitive resolution; others advocate for globally unique instances to prevent ambiguity. This paper compares how these four languages address type class coherence, revealing that despite syntactic differences, their strategies for circumventing limitations of unique instances are strikingly similar.