Concepts of Programming Languages

(Sean Pound) #1

720 Chapter 15 Functional Programming Languages


SUMMARY


Mathematical functions are named or unnamed mappings that use only condi-
tional expressions and recursion to control their evaluations. Complex functions
can be defined using higher-order functions or functional forms, in which func-
tions are used as parameters, returned values, or both.
Functional programming languages are modeled on mathematical func-
tions. In their pure form, they do not use variables or assignment statements to
produce results; rather, they use function applications, conditional expressions,
and recursion for execution control and functional forms to construct complex
functions. LISP began as a purely functional language but soon acquired a
number of imperative-language features added in order to increase its efficiency
and ease of use.
The first version of LISP grew out of the need for a list-processing lan-
guage for AI applications. LISP is still the most widely used language for that
area.
The first implementation of LISP was serendipitous: The original version
of EVAL was developed solely to demonstrate that a universal LISP function
could be written.
Because LISP data and LISP programs have the same form, it is possible
to have a program build another program. The availability of EVAL allows
dynamically constructed programs to be executed immediately.
Scheme is a relatively simple dialect of LISP that uses static scoping exclu-
sively. Like LISP, Scheme’s primary primitives include functions for construct-
ing and dismantling lists, functions for conditional expressions, and simple
predicates for numbers, symbols, and lists.
Common LISP is a LISP-based language that was designed to include
most of the features of the LISP dialects of the early 1980s. It allows both
static- and dynamic-scoped variables and includes many imperative features.
Common LISP uses macros to define some of its functions. Users are allowed
to define their own macros. The language includes reader macros, which are
also user definable. Reader macros define single-symbol macros.
ML is a static-scoped and strongly typed functional programming language
that uses a syntax that is more closely related to that of an imperative language
than to LISP. It includes a type-inferencing system, exception handling, a variety
of data structures, and abstract data types.
ML does not do any type coercions and does not allow function overload-
ing. Multiple definitions of functions can be defined using pattern matching of
the actual parameter form. Currying is the process of replacing a function that
takes multiple parameters with one that takes a single parameter and returns a
function that takes the other parameters. ML, as well as several other functional
languages, supports currying.
Haskell is similar to ML, except that all expressions in Haskell are evalu-
ated using a lazy method, which allows programs to deal with infinite lists.
Haskell also supports list comprehensions, which provide a convenient and
Free download pdf