You should have learnt about defining and working with algebraic data types.

The reading for this week is chapters 13 to 14 of the textbook, pages 287 to 356.

Remember to keep up with the reading! The textbook covers things in more detail than the lectures and has exercises to help you learn. Try doing the easy exercises in the textbook before you attempt the tutorial exercises.

You should have learnt about recursion, the definition of recursive functions, and recursive data structures (now you know that a list is a recursive data structure).

Remember to carry on reading chapters 4 to 7 in the textbook (pp. 67-176).

Extra note:

In the last two lectures you’ve been introduced to QuickCheck. QuickCheck does random testing on functions. This is a very useful tool for testing functions, but it relies on the fact that give some input a function always has the same output. This is of course true in Haskell. If f(x)=y then f(x) always equals y.

You give QuickCheck your function and a property that is true of all results of the function. QuickCheck generates a set of random inputs to your function and then checks that for every input the property is true. Of course, you have to be careful about the property you choose!

In other languages random testing is not quite as useful. A Java method, for example, does not always return the same result for some input. In Java f(x) does not always equal y. For example, f might depend on something in memory or some user input. In Haskell this is not the case.

One of the most powerful aspects of functional programming is this absence of state, that is the state of the world (memory, hard disk, user, network, etc.) does not affect the outcome of the function. Later on in the course you will learn how to deal with these necessary interactions with the world.

You should have learnt about lists, list comprehensions, and QuickCheck and you should now be able to attempt the list comprehension parts of the tutorial exercise.

The required reading is chapters 4 to 7 in the textbook (pp. 67-176).

Today’s material was particularly important because lists are a fundamental data structure in Haskell. Understanding how lists, comprehensions, and recursion (to come in the next lecture) work are key to understanding the rest of the course. Much of the material to come will be built upon these concepts. So:

Keep on top of the reading! There is a lot of material in the textbook so reading small sections frequently will allow you to get through it all in time for the next class. Try the exercises!

Get started on the tutorial exercises! You must have these done ready for your tutorial class. The sooner you start, the more time you’ll have to ask for help if you get stuck. And do ask for help.

There are no silly questions, only silly people who don’t ask questions!

Don’t forget that you can ask questions by posting comments on this blog. This is useful for your classmates as everyone will see the answers.

Extra notes:

Also in today’s lecture pairs were introduced. A pair (a,b) and in general an n-tuple (a,b,c,…) differs from a list in the following ways:

Lists can hold an arbitrary number of items, but tuples contain a fixed number (e.g. a pair contains two items, a triple or 3-tuple contains three items, an n-tuple contains n items).

The items in a list must all be of the same type, but in a tuple each item may have a different type.

will be Chapters 1, 2, and 3 (pp. 1-66). Three whole chapters might seem a bit daunting at first, but it is mostly introductory material and quite easy to read. Some of this material is directly relevant to this week’s lab exercise.

Printed copies of the lab exercise will be available from the ITO. In subsequent weeks, the tutorial exercises will be handed out in hard copy in Monday’s lecture; they will, of course, also be available from the course website.

Also: check out the Land of Lisp music video. The language Lisp was the first functional programming language. Amongst many other things, Lisp is famous for requiring a lot of parentheses!