CIFASIS   20631
CENTRO INTERNACIONAL FRANCO ARGENTINO DE CIENCIAS DE LA INFORMACION Y DE SISTEMAS
Unidad Ejecutora - UE
artículos
Título:
Improving typeclass relations by being open
Autor/es:
JASKELIOFF, MAURO; MARTÍNEZ, GUIDO; DE LUCA, GUIDO
Revista:
ACM SIGPLAN NOTICES
Editorial:
ASSOC COMPUTING MACHINERY
Referencias:
Lugar: New york; Año: 2018 vol. 53 p. 68 - 80
ISSN:
0362-1340
Resumen:
Mathematical concepts such as monads, functors, monoids, and semigroups are expressed in Haskell as typeclasses. Therefore, in order to exploit relations such as ?every monad is a functor?, and ?every monoid is a semigroup?, we need to be able to also express relations between typeclasses. Currently, the only way to do so is using superclasses. However, superclasses can be problematic due to their closed nature. Adding a superclass implies modifying the subclass? definition, which is either impossible if one does not own such code, or painful as it requires cascading changes and the introduction of boilerplate throughout the codebase. In this article, we introduce class morphisms, a way to relate classes in an open fashion, without changing class definitions. We show how class morphisms improve the expressivity, conciseness, and maintainability of code. Further, we show how to implement them while maintaining canonicity and coherence, two key properties of the Haskell type system. Extending a typechecker with class morphisms amounts to adding an elaboration phase and is an unintrusive change. We back this claim with a prototype extension of GHC.