ML modules and Haskell type classes have proven to be highly effective tools for program structuring. Modules emphasize explicit configuration of program components and the use of data abstraction. Type classes emphasize implicit program construction and ad hoc polymorphism. In this paper, we show how the implicitlytyped style of type class programming may be supported within the framework of an explicitly-typed module language by viewing type classes as a particular mode of use of modules. The modular setting offers several benefits: programmers have explicit control over which type class instances are available for use by type inference in a given scope, class hierarchies are expressible in terms of module hierarchies, and extensions to Haskell such as associated type synonyms arise naturally as uses of existing module-language constructs. We formalize our approach as an elaboration relation in the style of Harper and Stone, and provide a sound type inference algorithm as a guide to...
Manuel M. T. Chakravarty, Gabriele Keller, Simon L