Download ebooks file An Introduction to Functional Programming Through Lambda Calculus Michaelson all chapters
Download ebooks file An Introduction to Functional Programming Through Lambda Calculus Michaelson all chapters
com
https://ebookname.com/product/an-introduction-to-functional-
programming-through-lambda-calculus-michaelson/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/an-introduction-to-logic-programming-
through-prolog-j-m-spivey/
ebookname.com
https://ebookname.com/product/an-introduction-to-identification-
problems-via-functional-analysis-alfredo-lorenzi/
ebookname.com
https://ebookname.com/product/introduction-to-object-oriented-
programming-an-3rd-edition-timothy-budd/
ebookname.com
https://ebookname.com/product/mastering-skills-for-the-toefl-ibt-2nd-
edition-advanced-combined-book-moraig-macgillivray/
ebookname.com
Ideological Profile of Twentieth Century Italy Norberto
Bobbio
https://ebookname.com/product/ideological-profile-of-twentieth-
century-italy-norberto-bobbio/
ebookname.com
https://ebookname.com/product/scientific-pluralism-1st-edition-
stephen-h-kellert/
ebookname.com
https://ebookname.com/product/managing-research-development-and-
innovation-managing-the-unmanageable-third-edition-ravi-k-jain/
ebookname.com
https://ebookname.com/product/higher-education-in-virtual-worlds-
teaching-and-learning-in-second-life-1st-edition-charles-wankel/
ebookname.com
https://ebookname.com/product/big-skills-for-little-hands-i-can-color-
toddler-brighter-child/
ebookname.com
Benign Bigotry The Psychology of Subtle Prejudice 1st
Edition Kristin J. Anderson
https://ebookname.com/product/benign-bigotry-the-psychology-of-subtle-
prejudice-1st-edition-kristin-j-anderson/
ebookname.com
. .k' y‘ E 1h. ‘H‘l
‘ X x u H
, ‘ AN INTRo-‘U DN To 1,,
‘ Functional Programming
An Introduction to
FUNCTIONAL PROGRAMMING
Through
LAMBDA CALCULUS
Greg Michaelson
Herior-Warr University
Bibliographical Note
This Dover edition, first published in 2011, is an unabridged republication of
the work originally published in 1989 by Addison-Wesley Publishing Company,
Wokingham, England. The author has provided a new Preface for this edition.
iii
lV PREFACE TO THE DOVER EDITION
Content
Looking at this book from a markedly older a n d greyer perspective, by and
large I feel happy with it. In particular, I remain firmly wedded to the
pedagogy of learning by abstraction from concrete examples, of under-
standing A calculus through actually “doing” it in an explicitly operational
manner, and of gaining oversight of the layers between a simple, founda-
tional system and a rich language of variegated constructs and structures.
The book’s major eccentricity remains my reformulation of classic Acal-
culus syntax. In Church’s notation, applications in function bodies are
unbracketed, but functions are bracketed except where there is no ambigu-
ity. I chose instead to bracket applications in function bodies but to not
bracket functions except where there is ambiguity, as I felt these were more
in keeping with programming language conventions. In retrospect, I suspect
that this may prove unduly confusing to novices trying to use this book to
complement other sources.
I now think that the account of lazy evaluation could be simplified. There
is also merit in one reviewer’s suggestion2 that a pure lazy polymorphic lan-
guage might have been described given that both Lisp and SML are strict and
impure. However, when the book was written, MirandaTM was a commercial
product and Haskell had not been standardised.
Finally, my favourite chapter remains that on recursion.
Conclusion
When I was wee, my parents had lots of Dover books: Charles Babbage,
Lewis Carroll, Gustave Dore I a m tickled pink to be in the company of
such authors.
So, I would very much like to thank:
° John Crossley for suggesting that I approach Dover;
° John Grafton at Dover for reprinting this book, and for all his support.
Overview
This book aims to provide a gentle introduction to functional pro-
gramming. It is based on the premise that functional programming
provides pedagogic insights into many aspects of computing and offers
practical techniques for general problem solving.
The approach taken is to start with pure A calculus, Alonzo Church’s
elegant but simple formalism for computation, and to add syntactic layers
for function definitions, booleans, integers, recursion, types, characters,
lists and strings to build a fairly high level functional notation. Along the
way, a variety of topics are discussed including arithmetic, linear list and
binary tree processing, and alternative evaluation strategies. Finally,
functional programming in Standard ML and Common LISP, using
techniques developed throughout the book, are explored.
Readership
This book is intended for people who have taken a first course in an
imperative programming language like Pascal, FORTRAN or C and have
written programs using arrays and subprograms. There are no mathe-
matical prerequisites and no prior experience with functional programming
is required.
The material from this book has been taught to third year undergra-
duate Computer Science students and to postgraduate Knowledge-Based
Systems MSc students.
Approach
Within this book, A calculus is the primary vehicle for developing
functional programming. I was trained in a tradition which saw A calculus
as a solid base for understanding computing and my own teaching
experience confirms this. Many books on functional programming cover A
calculus but the presentation tends to be relatively brief and theoretically
oriented. In my experience, students whose first language is imperative
find functions, substitution and recursion conceptually difficult. Conse-
quently, I have given a fair amount of space to a relatively informal
treatment of these topics and include many worked examples. Functional
programming aficionados may find this somewhat tedious. However, this is
an introductory text.
This book does not try to present functional programming as a
complete paradigm for computing. Thus, there is no material on the formal
semantics of functional languages or on transformation and implemen-
tation techniques. These topics are ably covered in other books. By
analogy, one does not buy a book on COBOL programming in anticipation
of chapters on COBOL’s denotational semantics or on how to write
COBOL compilers. However, a number of topics which might deserve
more thorough treatment are omitted or skimmed. In particular, there
might be more discussion of types and typing schemes, especially abstract
data types and polymorphic typing, which are barely mentioned here. I feel
that these really deserve a book to themselves but hope that their coverage
is adequate for what is primarily an introductory text. There is no mention
of mutual recursion which is conceptually simple but technically rather
awkward to present. Finally, there is no discussion of assignment in a
functional context.
The functional notation developed in the book does not correspond
to any one implemented language. One of the book’s objectives is to
explore different approaches within functional programming and no single
language encompasses these. In particular, no language offers different
reduction strategies.
The final chapters consider functional programming in Standard
ML and Common LISP. Standard ML is a modern functional language
with succinct syntax and semantics based on sound theoretical principles.
It is a pleasing language in which to program and its use is increasing
within education and research. SML’s main pedagogic disadvantage is
that it lacks normal order reduction and so the low-level A calculus
representations discussed in earlier chapters cannot be fully investigated
in this language.
LISP was one of the earliest languages with an approximation to a
functional subset. It has a significant, loyal following, particularly in the
artificial intelligence community, and is programmed using many functio-
nal techniques. Here, Common LISP was chosen as a widely used modern
LISP. Like SML, it lacks normal order reduction. Unlike SML, it
PREFACE vii
Notations
In this book, different typefaces are used for different purposes. Text is in
Times Roman. New terms and important concepts are in Times Bold.
Programs and definitions are in Helvetica. Greek characters are used in
naming A calculus concepts:
or — alpha
3 — beta
x — lambda
n —eta
viii PREFACE
<digit> ::= 1 I 0
Acknowledgements
I had the good fortune to be taught Computer Science at the University of
Essex from 1970 to 1973. There I attended courses on the theory of
computing with Mike Brady and John Laski, which covered )t calculus,
recursive function theory and LISP, and on programming languages with
Tony Brooker, which also covered LISP. Subsequently, I was a post-
graduate student at St Andrews University from 1974 to 1977 where I
learnt about functional language design and implementation from Tony
Davie and Dave Turner. I would like to thank all these people for an
excellent education.
I would also like to thank my colleagues at Napier College, Glasgow
University and Heriot-Watt University with whom I have argued about
many of the ideas in this book, in particular Ken Barclay, Bill Findlay,
John Patterson, David Watt and Stuart Anderson.
I would, of course, like to thank everyone who has helped directly
with this book:
0 Paul Chisholm for patiently and thoroughly checking much of the
material: his help has been invaluable.
0 David Marwick for checking an early draft of Chapter 1 and Graeme
Ritchie for checking an early draft of Chapter 10.
0 Peter King, Chris Miller, Donald Pattie, Ian Crorie and Patrick
McAndrew, in the Department of Computer Science, Heriot-Watt
University, who provided and maintained the UNIX facilities used
to prepare this book.
0 Bob Colomb at CSIRO Division of Information Technology, Syd-
ney for providing a most pleasant environment within which to
complete this book.
PREFACE ix
Greg Michaelson
Edinburgh and Sydney
1988
Contents
Chapter 1 Introduction
1.1 Names and values in programming
1.2 Names and values in imperative and functional
languages
1.3 Execution order in imperative and functional
languages
1.4 Repetition in imperative and functional languages
1.5 Data structures in functional languages
1.6 Functions as values
1.7 The origins of functional languages
1.8 Computing and the theory of computing
1.9 A calculus
Summary
Chapter 2 Acalculus 15
2.1 Abstraction 16
2.2 Abstraction in programming languages 19
2.3 Introducing )\ calculus 20
2.4 A expressions 21
2.5 Simple A functions 23
2.6 Introducing new syntax 30
2.7 Notations for naming functions and B reduction 31
2.8 Functions from functions 31
2.9 Argument selection and argument pairing
functions 33
2.10 Free and bound variables 38
2.11 Name clashes and a conversion 43
2.12 Simplification through 1] reduction
Summary 45
Exercises 47
xii CONTENTS
Chapter 5 Types 87
5.1 Types and programming 88
5.2 Types as objects and operations 89
5.3 Representing typed objects 91
5.4 Errors 92
5.5 Booleans 94
5.6 Typed conditional expression 97
5.7 Numbers and arithmetic 98
5.8 Characters 101
5.9 Repetitive type checking 104
5.10 Static and dynamic type checking 107
5.11 Infix operators 107
5.12 Case definitions and structure matching 108
Summary 111
Exercises 113
Bibliography 305
Index 313
Trademark notice
MirandaTM is a trademark of Research Software.
INTERLISPTM is a trademark of the Xerox Corporation.
UNIXTM is a trademark of AT&T.
IBMTM is a trademark of the International Business Machines Corporation.
Chapter 1
Introduction
<command1> ;
<command2> ;
<command3> ;
<function1>(<function2>(<function3> ) )
Thus, each function receives values from and passes new values back to
the calling function. This is known as function composition or nesting.
In imperative languages, commands may change the value associ-
ated with a name by a previous command so each name may be and
usually will be associated with different values while a program is
running.
T : = X ;
X : = Y ;
Y : = T
4 INTRODUCTION TO FUNCTIONAL PROGRAMMING
T’s value depends on X’s value, X’s value depends on Y’s value and Y’s
value depends on T’s value. Thus, any change in the sequence completely
changes what happens. For example:
X : = Y ;
T : = X ;
Y : = T
sets X to Y and:
T := X ;
Y : T
X : = Y
sets Y to X.
Of course, not all command sequences have fixed execution orders.
In many imperative languages, the order in which expressions are
executed may not be defined. Thus, for expressions which involve
function calls, the order in which the functions are called may not be
defined. Functions have blocks of commands for bodies. Thus, the order
in which the different command blocks are executed may not be defined.
This may lead to problems when imperative languages allow side
effects — changes to variables made by expressions, for example, when a
function changes a non-local variable by assignment to one of its
parameters or to a global variable. If the order in which subexpressions
are evaluated is unpredictable, then the order in which side effects occur
is unpredictable. This makes it very hard to understand, develop and
debug programs which utilize them.
If commands’ expressions do not refer to each other, then the
command execution order does not matter. However, programs usually
depend on the precise order in which commands are carried out.
FUNCTION F( X,Y,Z:|NTEGER):|NTEGEFI ;
BEGIN END
FUNCTION A(P:INTEGER):INTEGER ;
INTRODUCTION 5
BEGIN END
FUNCTION B(Q:|NTEGER):INTEGER ;
BEGIN END
FUNCTION C(R:INTEGER):INTEGER ;
BEGIN END
F(A(D).B(D).C(D))
the order in which A(D), B(D) and C(D) are carried out does not matter
because the functions A, B and C cannot change their common actual
parameter D.
I := 0 ;
SUM := 0 ;
WHILE I < N DO
BEGIN
| := | + 1 ;
SUM := SUM + AU]
END
SUM(B,1,M)
B[1] + SUM(B,2,M) =
3m + B[2] + SUM(B,3,M) =
3m + B[2] + + B[M] + SUM(B,M+1,M) =
B[1] + B[2] + + B[M] + 0
Here, each recursive call to SUM creates new local versions of A, I and N,
INTRODUCTION 7
Thus:
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of En Turquie
d'Asie
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: French
EN
TURQUIE D’ASIE
NOTES DE VOYAGE EN ANATOLIE
(Le Koran.)
PARIS
G. CHARPENTIER, ÉDITEUR
13, RUE DE GRENELLE-SAINT-GERMAIN, 13
1883
Tous droits réservés.
DU MÊME AUTEUR
En préparation :
E. D.
PREMIÈRE PARTIE
LE PAYS. — LES MŒURS. — LES
HABITANTS
CHAPITRE PREMIER
LA VILLE DE BROUSSE
C’est aussi une des plus coquettes et des plus gracieuses villes
d’Asie, — vue à distance.
Quand, arrivant par la route de Moudania, on entre dans la vaste
plaine de Brousse, on aperçoit de très loin les blanches mosquées
aux minarets élancés qui, au milieu d’un fouillis de masures en bois,
s’étagent sur les contre-forts du massif de l’Olympe. L’œil ne saisit
d’abord que ces taches blanches qui se profilent au pied de ces
hautes et sévères montagnes. On dirait une troupe de nymphes
rieuses dansant une ronde autour d’un colosse.
Cette illusion et ce charme disparaissent, malheureusement,
aussitôt que l’on entre dans la ville. Des rues étroites, escarpées et
tortueuses ; des entassements de maisons sillonnées par des ruelles,
pleines d’immondices, où l’air circule à peine ; des constructions en
ruines, pans de murs branlants, attestations durables des
tremblements de terre et des incendies ; des masures en bois,
pourries et rongées par les ans, s’inclinant vers la terre, comme des
carcasses usées, ou s’affaissant à droite, à gauche, se soutenant
mutuellement par un miracle d’équilibre ; pour chaussée un cailloutis
défoncé par les pluies d’orages, impraticable aux voitures
européennes, — voilà l’aspect physique de la vieille ville.
Derrière les vitres des multiples fenêtres qui ornent chaque
maison, à travers les loques bariolées qui servent de rideaux,
apparaissent les visages, souvent gracieux, des grecques et des
arméniennes dont les grands yeux noirs scrutent curieusement le
passant, le déshabillent, pour ainsi dire. Quelques-unes, les vieilles
surtout, ne craignent point de mettre hardiment la tête hors la
fenêtre ; et ces figures ridées, vieillies avant l’âge, encadrées dans
des chevelures surchargées de fleurs, à la mode du pays, donnent à
l’étranger un premier mouvement de répulsion dont il a peine à se
défendre.
Après les longs kiefs sur les coteaux, les jardins de Set-bachi, le
théâtre, la plus grande distraction de l’élément chrétien à Brousse
consiste le dimanche à faire la promenade d’Adjemler. On appelle