1.3Features of Haskell
For reference, the main features of Haskell are listed below, along with particular
chapters of this book that give further details.
• Concise programs (chapters 2 and chapters 4)
Due to the high-level nature of the functional style, programs written in
Haskell are often much more concise than programs written in other
languages, as illustrated by the example in the previous section. Moreover,
the syntax of Haskell has been designed with concise programs in mind,
in particular by having few keywords, and by allowing indentation to be
used to indicate the structure of programs. Although it is difficult to make
an objective comparison, Haskell programs are often between two and ten
times shorter than programs written in other languages.
• Powerful type system (chapters 3 and chapters 8)
Most modern programming languages include some form of type system to
detect incompatibility errors, such as erroneously attempting to add a number
and a character. Haskell has a type system that usually requires little type
information from the programmer, but allows a large class of incompatibility
errors in programs to be automatically detected prior to their execution, using
a sophisticated process called type inference. The Haskell type system is
also more powerful than most languages, supporting very general forms of
polymorphism and overloading, and providing a wide range of special
purpose features concerning types.
• List comprehensions (chapter 5)
One of the most common ways to structure and manipulate data in computing
is using lists of values. To this end, Haskell provides lists as a basic concept
in the language, together with a simple but powerful comprehension notation
that constructs new lists by selecting and filtering elements from one or more
existing lists. Using the comprehension notation allows many common
functions on lists to be defined in a clear and concise manner, without the
need for explicit recursion.
• Recursive functions (chapter 6)
Most programs involve some form of looping. In Haskell, the basic
mechanism by which looping is achieved is through recursive functions that
are defined in terms of themselves. It can take some time to get used to
recursion, particularly for those with experience of programming in other
styles. But as we shall see, many computations have a simple and natural
definition in terms of recursive functions, especially when pattern matching
and guards are used to separate different cases into different equations.
• Higher-order functions (chapter 7)
Haskell is a higher-order functional language, which means that functions
can freely take functions as arguments and produce functions as results.
Using higher-order functions allows common programming patterns, such