Leading on from the slides by Peyton Jones, this lecture sets out how constructor classes and higher-order functions can help to treat effectful computation within a pure functional language; or potentially contain its influence within an imperative one.
Lecture 7: Polymorphism from Types to Kinds and Beyond12 October 2010
Continuing with types, and in particular some uses in the experimental language laboratory that is Haskell. This lecture covers more on polymorphism, in both object-oriented and functional languages.
Lecture 6: Types, Classes, Haskell8 October 2010
The three lectures today and next week are arranged around some features of the Haskell type system. They aren’t just specific to Haskell, though: several appear in other languages too, and they all address general programming issues. Haskell does make a good setting to examine them, as the language development has had a strong connection to programming language research, and it is sufficiently popular that there is a wide array of commentary out there on how well that works for users.
This lecture covered some background on type systems in programming languages and the different things languages do with them.
Read the rest of this entry »
Lecture 8: Multiparameter Type Classes, Constructor Classes4 February 2010
More (much, much more) on what you can do with type classes in Haskell: bulk operations on homogeneous collections; subclassing, subclass hierarchy, diamonds; nested class inference; code inheritance, multiway inheritance; multimethods; numeric overloading; arbitrary aspect-like separation of class, type and instance declarations.
The title topics of the lecture: multiparameter type classes (like
Collects s e) and constructor classes (like
Functor f). Both of these are language extensions, but well-supported and widely used.
Brief mention of yet more language extensions: explicit kinds; higher-rank polymorphism; existential types; and Generalized Algebraic Datatypes (GADTs).
All of these support the thesis of the week: type systems are not just about constraining the user to write safe programs — a well-built type system provides the scaffolding to safely build language features higher and further.
Read the following paper on multiparameter type classes.
- M. P. Jones. Type classes with functional dependencies.
In Programming Languages and Systems: Proceedings of the 9th
European Symposium on Programming, ESOP 2000, Lecture Notes in
Computer Science 1782, pages 230–244. Springer-Verlag, 2000
Links: Author’s web page; Publisher’s web page.
The final slides from the lecture contain a number of additional references.
Lecture 7: Haskell, Types and Classes1 February 2010
This block of four lectures are arranged around some features of the Haskell type system. They aren’t just specific to Haskell, though: several appear in other languages too, and they all address general programming issues. Haskell does make a convenient setting to examine them, as the language development has a strong connection to programming language research, and it is sufficiently popular that there is a wide array of commentary out in the blogosphere on how well that works out.
The lecture covered background on type systems in programming languages, what they are used for and how they might be tricky. The interaction of types, subtypes and inheritance in object-oriented languages is an example of this, which Java’s covariant subtyping of arrays conveniently demonstrates. Haskell’s type classes tackle many of the same issues, but from a substantially different direction. Arising originally from attempts to rationalise overloading of basic operations like equality, type classes have grown far beyond this to serve as a tool for imaginatively building a range of high-level programming abstractions.
The presentation itself was somewhat distorted by the non-operation of the projector screen. My apologies, I’ll report it and see if things go better on Thursday.
For Thursday’s lecture, read the following paper and set of slides.
- Philip Wadler and Stephen Blott. How to make ad-hoc polymorphism less ad-hoc. In Conference Record of the Sixteenth Annual ACM Symposium on Principles of Programming Languages, pages 60–76. ACM Press, 1989.
- Simon Peyton Jones. Wearing the hair shirt: a retrospective on Haskell. Invited talk at POPL 2003.
For further reading, see the lecture slides. These carry a range of embedded hyperlinks to references, research papers, and background material on the various examples.
In the spirit of the diagram from Cook’s paper, can anyone identify a pair of classes A and B, in any OO language or library, where A is (or should be) a subtype of B, while B inherits (or ought to, for code reuse) from A?