article

Type families with class, type classes with family

  • ACM SIGPLAN Notices
  • Association for Computing Machinery
Research footprint

At a glance

Citations
2
References
15
Comments
0
Paper overview

Abstract

Type classes and type families are key ingredients in Haskell programming. Type classes were introduced to deal with ad-hoc polymorphism, although with the introduction of functional dependencies, their use expanded to type-level programming. Type families also allow encoding type-level functions, but more directly in the form of rewrite rules. In this paper we show that type families are powerful enough to simulate type classes (without overlapping instances), and we provide a formal proof of the soundness and completeness of this simulation. Encoding instance constraints as type families eases the path to proposed extensions to type classes, like closed sets of instances, instance chains, and control over the search procedure. The only feature which type families cannot simulate is elaboration, that is, generating code from the derivation of a rewriting. We look at ways to solve this problem in current Haskell, and propose an extension to allow elaboration during the rewriting phase.

Record transparency

Publication details

DOI
10.1145/2887747.2804304
OpenAlex
W3124053277
Document type
article
Language
EN
Source
ACM SIGPLAN Notices
Last metadata update
Community

Comments

Log in to join the discussion.

  1. No comments yet. Start the discussion.