Haskell with only one typeclass
2007-03-01 07:56:47 GMT
Defining new typeclasses is regarded as an important part of Haskell programming, as the normal way of introducing overloaded functions. This message shows that if the ability to define typeclasses is removed, no expressivity is lost. If Haskell had only one, pre-defined typeclass with only one method, we could still do normal Haskell programming with standard and user-defined overloaded numerical functions, monads, monad transformers, etc. Haskell with only one typeclass can express all of Haskell98 typeclass programming idioms including constructor classes, plus multi-parameter type classes and some functional dependencies. If we additionally admit TypeCast as a pre-defined constraint, the rest of functional dependencies are expressible. Besides clarifying the role of typeclasses in Haskell as method bundles, this message proposes a model of overloading resolution that is simpler than that of Hall et al. Perhaps this model might be of interest to Haskell' committee. The present approach is inspired by HList's class Apply, which seems to be, after a small adjustment, the universal class. For clarity of terminology, we call as Haskell1 the language Haskell98 with no typeclass declarations but with a single, already declared typeclass C (which has two parameters related by a functional dependency). The programmers may not declare any typeclasses; but they may add instances to C and use them. We show on a series of examples that despite the lack of typeclass declarations, Haskell1 can express all the typeclass code of Haskell98 and then multi-parameter type classes and some (most useful?) functional dependencies. Haskell98 methods are defined as ordinary functions in Haskell1.(Continue reading)
RSS Feed