Skip to main content



Shape-Shifters: Type Classes for Declaration-Site Variance

(Anonymous OOPSLA 2015 Submission)

Discussion led by Fabian Muehlboeck on May 11, 2015

Abstract:

Type classes are an excellent feature of Haskell. In particular, they are one of the best solutions for type-safe equality. Unfortunately, they have proven difficult to adapt to objectoriented programming.

In this paper, we investigate this problem applied to the common architecture of collection classes and interfaces using declaration-site variance. At the same time, we enable developers to build a default implementation of a type class into a class or interface, such that the compiler can erase type classes whenever their default implementation is used. This investigation makes apparent two additional requirements for a type-class feature design to be practical: an ability to supply a non-built-in type-class implementation, and a need to explicitly distinguish between callee’s and caller’s typeclass implementations.

We present a design that accommodates these requirements. This design is regrettably complex, though the complexity seems unavoidable once one identifies all of the design constraints. The goal of this paper is to educate readers about aspects of the design space that have been ignored in the past, and to offer a concrete step towards addressing those aspects.

PDF