An Introduction to Functional Programming Through Lambda Calculus Michaelson - The ebook is available for instant download, read anywhere
An Introduction to Functional Programming Through Lambda Calculus Michaelson - The ebook is available for instant download, read anywhere
com
https://ebookname.com/product/an-introduction-to-functional-
programming-through-lambda-calculus-michaelson/
OR CLICK HERE
DOWLOAD EBOOK
https://ebookname.com/product/an-introduction-to-logic-
programming-through-prolog-j-m-spivey/
https://ebookname.com/product/an-introduction-to-identification-
problems-via-functional-analysis-alfredo-lorenzi/
https://ebookname.com/product/introduction-to-object-oriented-
programming-an-3rd-edition-timothy-budd/
https://ebookname.com/product/unity-game-audio-implementation-a-
practical-guide-for-beginners-1st-edition-andrew-coggan/
Virtual networks pluralistic approach for the next
generation of Internet 1st Edition Duarte
https://ebookname.com/product/virtual-networks-pluralistic-
approach-for-the-next-generation-of-internet-1st-edition-duarte/
https://ebookname.com/product/revolution-in-danger-writings-from-
russia-1919-1921-victor-serge/
https://ebookname.com/product/context-aware-computing-1st-
edition-ling-feng/
https://ebookname.com/product/harmony-of-colour-89-oriental-
dynasty-1st-edition-nuclear-media/
https://ebookname.com/product/the-shut-up-and-shoot-documentary-
guide-a-down-dirty-dv-production-anthony-q-artis/
Setting Profitable Prices Website A Step by Step Guide
to Pricing Strategy Without Hiring a Consultant 1st
Edition Jensen
https://ebookname.com/product/setting-profitable-prices-website-
a-step-by-step-guide-to-pricing-strategy-without-hiring-a-
consultant-1st-edition-jensen/
. .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
3 "Clinical Lecture on Diseases of the Heart, with Ague (and Hæmaturia)," London
Lancet, 1832, p. 500.
4 "Intermittent Hæmaturia," Medico-Chirurg. Trans. London, 1865.
Two degrees of the disease are met with—a milder form, in which
other symptoms as well as the hæmaturia are less pronounced, and
of which instances occur in the Middle States as well as the South
and West of the United States. Of this kind seem to be the cases
studied by Harley and other English physicians. In addition to this,
there is a second, more malignant, form, attended by great
prostration, vomiting, and yellowness of the skin, along with copious
discharges of bloody urine. Instances of the latter are numerous in
the Southern States of this country, where they have recently been
studied with much care; also in the East and West Indies and in
tropical countries generally. In neither degree of the disease is it
necessary that the red corpuscles of the blood should be present.
They may be represented by their coloring matters alone, when the
condition is called a hæmoglobinuria or a hæmaturia.
Negroes are not exempt from this milder form of the disease, as
they seem to be from the more malignant form of the South. While
writing this paper I was consulted by a negro thirty-one years old
who had a true malarial hæmoglobinuria, which yielded promptly to
the treatment by quinine. But this was the only negro out of seven
cases.
Casts of the uriniferous tubules are also often present. They are
usually made up of aggregated red blood-discs or the granular
matter referred to; but they may also be hyaline or hyaline with a
moderate amount of granular matter attached. Granular urates also
at times contribute to the sediment and also adhere to the casts.
Renal and vesical epithelium may occur. Crystals of oxalate of lime
and of uric acid are sometimes present, while blood-crystals have
been found by Gull6 and Grainger Stewart, and a hæmatin crystal
once by Strong.7
6 Guy's Hosp. Reports, 1866, p. 381.
11 "Verhandl. des Vereins für innere Medicin," Deut. Med. Wochenschr., No. 52, Dec.
29, 1883.
It being certain that the blood comes from the kidney, we have to
distinguish it from that due to cancer, to calculus-irritation, and to
cachexias, as purpura and scurvy; or to grave forms of infectious
disease, septicæmia, pyæmia, etc.; or, finally, to poisonous
substances introduced into the blood, such as arsenic, iodine,
arseniuretted hydrogen, carbonic acid and carbonic oxide gas, and
even certain species of edible fungi.
Where these means failed I have not found the other methods of
treatment commonly resorted to in obstinate malarial disease to be
any more efficient. I allude to the treatment by arsenic or by iron
and arsenic. Indeed, in the only two cases in which, after failure with
the quinine treatment, iron and arsenic were used at my suggestion,
they failed absolutely. In the one case, under the care of James L.
Tyson, this treatment was carried out most faithfully. After four
weeks' treatment with quinine without effect, Fowler's solution was
given, at first in 5-drop doses three times daily, subsequently
increased to 10 and 15, along with 20- and 30-drop doses of tincture
of the chloride of iron, until oedema of the eyelids occurred, when
the arsenic was discontinued, but the iron continued. In two or three
days the arsenic was recommenced in 3- and 4-drop doses for three
or four weeks longer without effect. Fluid extract of ergot in 20-drop
doses was then substituted for the iron, alternating with the arsenic
for two weeks longer, when some slight favorable change was
apparent, but it was temporary. Repeatedly throughout the
treatment the patient complained of weariness and backache, cold
feet and knees, headache and acceleration of pulse, and a feeling of
utter wretchedness; and then again he would feel quite comfortable
for a day or two, but with little or no change in the urine, except
occasionally in the morning, when it would sometimes be quite light-
hued, but after breakfast would again assume its bloody character. A
sojourn at the seaside for two weeks was without effect.
It will appear from the above that ergot, which has been found
useful in some forms of hæmaturia, is of little service here, as is
attested by two other cases in which I tried it faithfully. At the same
time, it is a remedy which should be tried in case of failure with
others.
The following are some of the chalybeate and alum springs the
waters of which may be expected to be of service in hæmaturia:
Orchard Acid Springs, New York; Rockbridge Alum Springs, Pulaski
Alum Springs, Bath Alum Springs, Stribling Springs, and Bedford
Alum Springs, all in Virginia. In all of these waters iron and alum are
both present, accompanied, in many instances, by free sulphuric
acid, by which their efficiency is increased. In one of my cases the
hemorrhage disappeared temporarily under the use of the water
from the Bedford Springs, Penna., but again returned. These waters
contain a little iron, but no alum. Subsequently, the same patient
was promptly relieved by quinine, which had not been previously
tried.
But the cases most promptly relieved by the alum waters are the
non-malarial cases depending, upon hemorrhagic diathesis without
other local disease. A remarkable instance of this kind was related to
me by letter by J. Macpherson Scott of Hagerstown, Md. After
enormous doses of quinine had been used under the supposition
that it was malarial, it was promptly and totally cured.
CHYLURIA.
Water 947.4
Solid matter 52.6
Urea 7.73
Albumen 13.00
Uric acid 0.00
Extractive matter with uric acid 11.66
Fat insoluble in hot and cold alcohol, but soluble in ether 9.20
Fat insoluble in cold alcohol 2.70 13.90
Fat soluble in cold alcohol 2.00
Alkaline sulphates and chlorides 1.65
Alkaline phosphates
4.66
Earthy phosphates
1 Urinary and Renal Derangements and Calculous Disorders, Philada., 1885, p. 73.
Such urines are of course albuminous, as will have been seen from
the table. They therefore coagulate when boiled or on the addition
of an acid. They also exhibit a tendency to spontaneous coagulation
more or less complete, which is apt to be followed by later
disintegration of the clot. The proportion of solids is larger than in
ordinary urines.
Water 978.8
Solid matter 21.2
Urea 6.95
Albumen 0.00
Uric acid .15
Extractive matter with uric acid 7.31
Fat insoluble in hot and cold alcohol, but soluble in ether
Fat insoluble in cold alcohol .00
Fat soluble in cold alcohol
Alkaline sulphates and chlorides 1.45
Earthy phosphates .15
DISTRIBUTION OF THE DISEASE.—By far the largest majority of instances
of the disease originate in tropical and subtropical climates. Thus,
India, China, and South America—and in South America, Brazil, and
Guiana—are countries in which it is common. It is said to be rarer on
the coast of South America than in the interior; yet it is especially
partial to insular countries, and most of the cases observed in this
country originate in the West Indies—in Barbadoes and Cuba, in
Bermuda and the island of Trinidad. Many cases occur in Bahia,
Guadeloupe, Madagascar, the Isle of Bourbon, and Mauritius.
Indeed, the first important study of the subject was based on cases
observed in the latter island by Chapotin.2 In Africa both Egypt and
the Cape of Good Hope are favorite localities, and in Australia,
Brisbane has furnished many cases.
2 Thèse, Topographie médicale de l'Ile de France, 1812.
The subjects of the disease are apt to be pale and relaxed as to their
tissues, but while this may be a possible result of the disease, it can
hardly be regarded as a predisposing cause.
Prout,4 among the earlier writers on this subject, and more recently
Bence Jones,5 Waters, Bouchardat, Robin, Bernard, and Egel, did not
consider a positive lesion necessary, but ascribed the condition to a
vice of nutrition and blood-making, accompanied by a slight
consequent textural alteration in the blood-vessels of the kidney,
through which the elements of the chyle transuded. Waters6 says
that "the main pathological feature of the complaint is a relaxed
condition of the capillaries of the kidney," which permits the
transudation.
4 Stomach and Renal Diseases, 4th ed., London, 1843.
5 Lectures on Pathology and Therapeutics, 1868, p. 256.
Bernard and Robin also compared the blood of such cases to that of
geese artificially fattened, being that condition of blood which is
normal after digestion but transient. Egel also held similar views,
ascribing the imperfect elaboration to the effect of hot climates.
One of the most singular features in the history of the filaria is its
nocturnal habit. It is found in the blood only at night, unless, as
Mackenzie has shown, night be converted into day—that is, if the
hours of sleeping and waking be reversed. In Mackenzie's case the
worms appeared about seven o'clock in the evening, increased up to
midnight, and disappeared by eight or nine o'clock in the morning.
What becomes of them at the time when they are undiscoverable in
the blood is as yet unknown.
On the other hand, the filaria embryo is often found in the blood of
persons apparently in perfect health. Manson tells us that out of
every ten Chinamen taken at random, at Amoy, the blood of one will
contain filariæ.
While chyluria has made its appearance, for the first time, in a
number of cases during pregnancy, this condition in other instances
has caused it to disappear, especially toward the later months;
whence it would seem that the pressure of the rising womb has a
favorable effect.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com