Thursday, April 20, 2006

The Teaching of Programming

Having decided that computer science isn't really my thing (I prefer it as a hobby, rather than a career), I'm now training to be a teacher and, as such, spend a certain amount of time thinking about ways to present material. One of the topics that is of no small interest to me is the teaching of programming, as distinct from teaching programming languages.

I spent some of the 2.5 hour bus trip back from classes in Hobart today thinking about ways to present monads. As a result, I've decided to write my very own version of that mainstay of the Haskell community — Yet Another Monads Tutorial. The goals of this project are twofold:
  1. to try to solidify my understanding of monads, their uses and theory; and
  2. to present programming in a way that very few or, more likely, no students will experience before advanced undergraduate CS classes.
My current thinking is to introduce functional programming in terms of expression reduction (using Hugs or, maybe, GHCi). This will segue into a discussion of evaluation semantics (specifically, lazy evaluation) which will raise the problem of sequenced computations. Monads (as we already know) provide a solution to this problem which will be demonstrated with some work in the IO monad. To really understand how Monads work in Haskell, we'll have to take a brief detour through type classes before we look at defining our own instances of Monad.

The main example (and the only one that I've thought most about) will be a Monad that allows us to compose transformation matrices for 3D work in monadic style. In this Monad, we'll be able to create a transformation matrix by doing something like: myTransform = do
    identityMatrix;
    rotateAbout Z 90;
    scale X 1.5;
    translate Y 20
rather than explicitly creating the matrix for each transformation and multiplying them together or, worse, poking at the individual members of the transformation matrix. Furthermore, this example lends itself quite well to extension. Instead of calculating a matrix which performs the appropriate transformations, we might instead create an data-structure encoding the calculation which will, when evaluated, yield such a matrix. This data-structure could then be evaluated (like, if I understand correctly runST does for the ST monad) or it could be subjected to symbolic manipulation (perhaps allowing the students to implement a simple optimiser).

This will probably turn into my major project for next semester (developing plans and materials for an entire unit). If it does, I'll probably make it available online somewhere.

Tags:

2 comments:

Anonymous said...

I'm taking a graduate PL class with William Cook, and he gave an excellent introductory lecture on Monads. He treated them as a generalization of threading state (or errors, for example) through a purely functional language. One of the key points was motivating first through several concrete examples and then generalizing over those. Finally, you return to the concrete examples with your general framework. It also lead right into monad transformers, because you'd want to combine your concrete examples.

The slides are available on the schedule of our class website. Of course, the lecture relied on the context of the class (developed through Winskel's Formal Semantics and Pierce's TAPL). And, unfortunately, the slides don't do justice to the visual metaphors developed in the lecture.

Anonymous said...

BTW, I don't know if it's just Firefox, but the gray text on your blog is quite difficult to read. The lack of contrast between the text and the background actually hurts my eyes if I try to focus on it for very long.

I don't mean to be a pain or anything. Just thought you might want to know...