Bidirectional Type Class Instances (Extended Version)
Koen Pauwels, Georgios Karachalias, Michiel Derhaeg, Tom Schrijvers

TL;DR
This paper introduces Bidirectional Type Class Instances for Haskell, enabling more flexible and expressive interactions between GADTs and type classes by interpreting instances as logical bi-implications.
Contribution
It proposes a conservative extension to Haskell's type classes, including a formal design, type inference algorithm, and proof-of-concept implementation.
Findings
Enhanced ability to define instances for GADTs
Formalization of bidirectional type class semantics
Implementation demonstrating practical feasibility
Abstract
GADTs were introduced in Haskell's eco-system more than a decade ago, but their interaction with several mainstream features such as type classes and functional dependencies has a lot of room for improvement. More specifically, for some GADTs it can be surprisingly difficult to provide an instance for even the simplest of type classes. In this paper we identify the source of this shortcoming and address it by introducing a conservative extension to Haskell's type classes: Bidirectional Type Class Instances. In essence, under our interpretation class instances correspond to logical bi-implications, in contrast to their traditional unidirectional interpretation. We present a fully-fledged design of bidirectional instances, covering the specification of typing and elaboration into System FC, as well as an algorithm for type inference and elaboration. We provide a proof-of-concept…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsLogic, programming, and type systems · Advanced Software Engineering Methodologies · Software Engineering Research
