Applicative, or functional
, programs have many virtues. They are concise, secure and elegant. Applicative programs are easier to understand and easier to prove correct than programs written in imperative programming languages.
However, functional languages have some shortcomings
. It may be said that some programming problems appear to be inherently state-based. The uniformity of representation which functional programming languages offer then becomes a handicap. Although a functional implementation of a solution to such a problem would be possible it might be an unnatural or obscure encoding of the solution.
languages have their strengths. They often provide explicit support for the construction of programs on a large scale by providing simple, robust modules which allow a large programming task to be decomposed into self-contained units which may be implemented in isolation. If these units are general and well designed they may be included in a library, facilitating their re-use in other programs. Modules also enable programs to be efficient) recompiled by avoiding the need to recompile parts of the program which have not changed.
These notes address the issues of combining
the virtues of functional programming with the virtues of imperative programming. This is implemented using both the Standard ML
programming language and Extended ML
Standard ML Programming Language:
For most of these notes the focus will be on using the functional subset of the language so the notes will spend some time discussing functions, in particular recursive functions, and giving verification techniques for these. In the early sections of these notes the examples are all small integer functions. Later, Standard ML's sophisticated type system is presented.
The mechanism by which applicative programs are evaluated is discussed. This leads into the consideration of alternative evaluation strategies one of which is so-called lazy evaluation
. This strategy has a profound effect on the style of programming which must be deployed.
The other elements of the Standard ML which are discussed are the mechanism used to signal that an exceptional case has been detected during processing and no consistent answer can be returned and the imperative features such as references and interactive input and output.
Extended ML Wide-spectrum Language:
These notes will also address the early part of the program development cycle: the commissioning of a software system and the gradual, disciplined construction which takes place before the final realization as a program. The Extended ML language will be used here to specify problems whose solution is to be implemented in Standard ML.