Introducing functional programming
To establish the fundamentals of functional programming: expressions and
their evaluation; function definitions.
To establish some terminology: function, type, expression, calculation and
evaluation, among the other words introduced in Section 1.1.
To introduce the Miranda system: commands, expression evaluation and the
To introduce the idea that evaluations can be written by hand; we call these
hand evaluations calculations.
To stress the importance of doing: programming as a skill is only learned
by reading, modifying and writing programs. Also calculation can be seen as a
way of actively exploring how a definition works.
To begin a discussion about how function definitions can be designed
I feel that the matter of design
is a most important point to stress
right from the start of any functional programming course.
A common complaint amongst students is that they find it hard just to get
going on writing a function definition, so giving them strategies such as
modifying, simplifying, generalising or using other functions gives one kind
of handle on the task.
Calculation gives a concrete model of how functional programs work; this can
help students who find it difficult to appreciate how a definition works. I try
to encourage students to try examples as another strategy when they are stuck.
(Later in the text examples are used to guide the way that definitions are
Links with imperative programming
Obviously students come from different backgrounds. Appendix A provides a
commentary on the relationship between Pascal-style imperative programming and
Miranda. It is very useful to make these distinctions, both about issues like
syntax (especially the different ways that function calls are written) and
terminology (what is a function in the two cases?) as well as
about the different ways that problems are tackled in the different languages.
At Kent we have tried as much as we can to link our functional and imperative
programming presentations; this comes into its own when looking at dynamic
data structures, but can be useful right from the start.
This is a good point at which to introduce some of the other appendices,
glossary and the list of error messages. Also included is the standard
environment; it is worth mentioning this, but making clear that some of the
notations there will not be fully explained until Part II of the text.
The first example file, as well as all the code from the text is available
by clicking on the title of this paragraph.
Written 18 May 1995.