100% found this document useful (2 votes)
139 views

Programming in Haskell 2nd Edition Graham Hutton instant download

The document provides information about the book 'Programming in Haskell, 2nd Edition' by Graham Hutton, which is a comprehensive guide to Haskell, a purely functional programming language. It covers both basic and advanced topics, making it accessible to readers with no prior programming experience. The book has been updated with recent features, examples, and exercises, and is intended for both teaching and practical application in the industry.

Uploaded by

smotrsargin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
139 views

Programming in Haskell 2nd Edition Graham Hutton instant download

The document provides information about the book 'Programming in Haskell, 2nd Edition' by Graham Hutton, which is a comprehensive guide to Haskell, a purely functional programming language. It covers both basic and advanced topics, making it accessible to readers with no prior programming experience. The book has been updated with recent features, examples, and exercises, and is intended for both teaching and practical application in the industry.

Uploaded by

smotrsargin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Programming in Haskell 2nd Edition Graham Hutton

pdf download

https://ebookfinal.com/download/programming-in-haskell-2nd-
edition-graham-hutton/

Explore and download more ebooks or textbooks


at ebookfinal.com
We have selected some products that you may be interested in
Click the link to download now or visit ebookfinal.com
for more options!.

Malaysian favourites Hutton

https://ebookfinal.com/download/malaysian-favourites-hutton/

Intertextuality 2nd Edition Graham Allen

https://ebookfinal.com/download/intertextuality-2nd-edition-graham-
allen/

Haskell Bookcamp MEAP v06 Philipp Hagenlocher

https://ebookfinal.com/download/haskell-bookcamp-meap-v06-philipp-
hagenlocher/

Programming in Lua 2nd Edition Roberto Ierusalimschy

https://ebookfinal.com/download/programming-in-lua-2nd-edition-
roberto-ierusalimschy/
Clinical Psychology 2nd Edition Graham Davey

https://ebookfinal.com/download/clinical-psychology-2nd-edition-
graham-davey/

C Programming in Linux 2nd Edition David Haskins

https://ebookfinal.com/download/c-programming-in-linux-2nd-edition-
david-haskins/

In Contradiction A Study of the Transconsistent 2nd


edition Graham Priest

https://ebookfinal.com/download/in-contradiction-a-study-of-the-
transconsistent-2nd-edition-graham-priest/

Cybercrime and Digital Deviance 2nd Edition Graham

https://ebookfinal.com/download/cybercrime-and-digital-deviance-2nd-
edition-graham/

EU UK Competition Law 2nd Edition Cosmo Graham

https://ebookfinal.com/download/eu-uk-competition-law-2nd-edition-
cosmo-graham/
Programming in Haskell 2nd Edition Graham Hutton
Digital Instant Download
Author(s): Graham Hutton
ISBN(s): 9781316626221, 1316626229
Edition: 2
File Details: PDF, 8.12 MB
Year: 2016
Language: english
Programming in Haskell

Second Edition

Haskell is a purely functional language that allows programmers to rapidly develop


clear, concise and correct software. The language has grown in popularity in recent
years, both in teaching and in industry. This book is based on the author’s experience of
teaching Haskell for more than 20 years. All concepts are explained from first principles
and no programming experience is required, making this book accessible to a broad
spectrum of readers. While Part I focuses on basic concepts, Part II introduces the reader
to more advanced topics.
This new edition has been extensively updated and expanded to include recent and
more advanced features of Haskell, new examples and exercises, selected solutions,
and freely downloadable lecture slides and code. The presentation is clean and simple,
while also being fully compliant with the latest version of the language, including recent
changes concerning applicative, monadic, foldable and traversable types.

Graham Hutton is Professor of Computer Science at the University of Nottingham.


He has taught Haskell to thousands of students and received numerous best lecturer
awards. Hutton has served as an editor of the Journal of Functional Programming, chair
of the Haskell Symposium and the International Conference on Functional Program-
ming, vice-chair of the ACM Special Interest Group on Programming Languages, and
he is an ACM Distinguished Scientist.
Programming in Haskell
Second Edition

GRAHAM HUTTON
University of Nottingham
University Printing House, Cambridge CB2 8BS, United Kingdom
One Liberty Plaza, 20th Floor, New York, NY 10006, USA
477 Williamstown Road, Port Melbourne, VIC 3207, Australia
4843/24, 2nd Floor, Ansari Road, Daryaganj, Delhi - 110002, India
79 Anson Road, #06-04/06, Singapore 079906

Cambridge University Press is part of the University of Cambridge.


It furthers the University’s mission by disseminating knowledge in the pursuit of
education, learning, and research at the highest international levels of excellence.

www.cambridge.org
Information on this title: www.cambridge.org/9781316626221
10.1017/9781316784099
© Graham Hutton 2007, 2016
This publication is in copyright. Subject to statutory exception
and to the provisions of relevant collective licensing agreements,
no reproduction of any part may take place without the written
permission of Cambridge University Press.
First published 2007
Second edition 2016
Printed in the United Kingdom by Clays, St Ives plc
A catalogue record for this publication is available from the British Library
ISBN 978-1-316-62622-1 Paperback
Cambridge University Press has no responsibility for the persistence or accuracy
of URLs for external or third-party Internet Web sites referred to in this publication,
and does not guarantee that any content on such Web sites is, or will remain,
accurate or appropriate.
Contents

Foreword page xiii


Preface xv

Part I Basic Concepts 1

1 Introduction 3
1.1 Functions 3
1.2 Functional programming 4
1.3 Features of Haskell 6
1.4 Historical background 8
1.5 A taste of Haskell 9
1.6 Chapter remarks 13
1.7 Exercises 13

2 First steps 14
2.1 Glasgow Haskell Compiler 14
2.2 Installing and starting 14
2.3 Standard prelude 15
2.4 Function application 16
2.5 Haskell scripts 17
2.6 Chapter remarks 21
2.7 Exercises 21

3 Types and classes 22


3.1 Basic concepts 22
3.2 Basic types 23
3.3 List types 25
3.4 Tuple types 26
3.5 Function types 27
3.6 Curried functions 27
3.7 Polymorphic types 29
3.8 Overloaded types 30
3.9 Basic classes 31
3.10 Chapter remarks 36
viii Contents

3.11 Exercises 36

4 Defining functions 38
4.1 New from old 38
4.2 Conditional expressions 38
4.3 Guarded equations 39
4.4 Pattern matching 40
4.5 Lambda expressions 42
4.6 Operator sections 44
4.7 Chapter remarks 45
4.8 Exercises 45

5 List comprehensions 47
5.1 Basic concepts 47
5.2 Guards 48
5.3 The zip function 50
5.4 String comprehensions 51
5.5 The Caesar cipher 52
5.6 Chapter remarks 56
5.7 Exercises 57

6 Recursive functions 59
6.1 Basic concepts 59
6.2 Recursion on lists 61
6.3 Multiple arguments 63
6.4 Multiple recursion 64
6.5 Mutual recursion 65
6.6 Advice on recursion 66
6.7 Chapter remarks 71
6.8 Exercises 71

7 Higher-order functions 73
7.1 Basic concepts 73
7.2 Processing lists 74
7.3 The foldr function 76
7.4 The foldl function 79
7.5 The composition operator 81
7.6 Binary string transmitter 82
7.7 Voting algorithms 86
7.8 Chapter remarks 89
7.9 Exercises 89

8 Declaring types and classes 92


8.1 Type declarations 92
Contents ix

8.2 Data declarations 93


8.3 Newtype declarations 95
8.4 Recursive types 96
8.5 Class and instance declarations 99
8.6 Tautology checker 101
8.7 Abstract machine 106
8.8 Chapter remarks 108
8.9 Exercises 109

9 The countdown problem 111


9.1 Introduction 111
9.2 Arithmetic operators 112
9.3 Numeric expressions 113
9.4 Combinatorial functions 114
9.5 Formalising the problem 115
9.6 Brute force solution 115
9.7 Performance testing 116
9.8 Combining generation and evaluation 117
9.9 Exploiting algebraic properties 118
9.10 Chapter remarks 119
9.11 Exercises 120

Part II Going Further 121

10 Interactive programming 123


10.1 The problem 123
10.2 The solution 124
10.3 Basic actions 125
10.4 Sequencing 126
10.5 Derived primitives 127
10.6 Hangman 128
10.7 Nim 129
10.8 Life 133
10.9 Chapter remarks 137
10.10 Exercises 137

11 Unbeatable tic-tac-toe 139


11.1 Introduction 139
11.2 Basic declarations 140
11.3 Grid utilities 141
11.4 Displaying a grid 142
11.5 Making a move 143
11.6 Reading a number 144
11.7 Human vs human 144
x Contents

11.8 Game trees 145


11.9 Pruning the tree 147
11.10 Minimax algorithm 148
11.11 Human vs computer 150
11.12 Chapter remarks 151
11.13 Exercises 151

12 Monads and more 153


12.1 Functors 153
12.2 Applicatives 157
12.3 Monads 164
12.4 Chapter remarks 174
12.5 Exercises 175

13 Monadic parsing 177


13.1 What is a parser? 177
13.2 Parsers as functions 177
13.3 Basic definitions 179
13.4 Sequencing parsers 179
13.5 Making choices 181
13.6 Derived primitives 183
13.7 Handling spacing 186
13.8 Arithmetic expressions 187
13.9 Calculator 191
13.10 Chapter remarks 194
13.11 Exercises 194

14 Foldables and friends 196


14.1 Monoids 196
14.2 Foldables 200
14.3 Traversables 206
14.4 Chapter remarks 210
14.5 Exercises 210

15 Lazy evaluation 212


15.1 Introduction 212
15.2 Evaluation strategies 213
15.3 Termination 216
15.4 Number of reductions 217
15.5 Infinite structures 219
15.6 Modular programming 220
15.7 Strict application 223
15.8 Chapter remarks 226
15.9 Exercises 226
Contents xi

16 Reasoning about programs 228


16.1 Equational reasoning 228
16.2 Reasoning about Haskell 229
16.3 Simple examples 230
16.4 Induction on numbers 231
16.5 Induction on lists 234
16.6 Making append vanish 238
16.7 Compiler correctness 241
16.8 Chapter remarks 246
16.9 Exercises 246

17 Calculating compilers 249


17.1 Introduction 249
17.2 Syntax and semantics 249
17.3 Adding a stack 250
17.4 Adding a continuation 252
17.5 Defunctionalising 254
17.6 Combining the steps 257
17.7 Chapter remarks 261
17.8 Exercises 261

Appendix A Selected solutions 263


A.1 Introduction 263
A.2 First steps 264
A.3 Types and classes 265
A.4 Defining functions 266
A.5 List comprehensions 267
A.6 Recursive functions 267
A.7 Higher-order functions 268
A.8 Declaring types and classes 269
A.9 The countdown problem 270
A.10 Interactive programming 270
A.11 Unbeatable tic-tac-toe 271
A.12 Monads and more 272
A.13 Monadic parsing 273
A.14 Foldables and friends 274
A.15 Lazy evaluation 275
A.16 Reasoning about programs 276
A.17 Calculating compilers 279

Appendix B Standard prelude 280


B.1 Basic classes 280
B.2 Booleans 281
B.3 Characters 282
xii Contents

B.4 Strings 283


B.5 Numbers 283
B.6 Tuples 284
B.7 Maybe 284
B.8 Lists 285
B.9 Functions 287
B.10 Input/output 287
B.11 Functors 288
B.12 Applicatives 289
B.13 Monads 290
B.14 Alternatives 290
B.15 MonadPlus 291
B.16 Monoids 292
B.17 Foldables 294
B.18 Traversables 297

Bibliography 298
Index 300
For Annette, Callum and Tom
Foreword

It is nearly a century ago that Alonzo Church introduced the lambda calculus,
and over half a century ago that John McCarthy introduced Lisp, the world’s
second oldest programming language and the first functional language based
on the lambda calculus. By now, every major programming language including
JavaScript, C++, Swift, Python, PHP, Visual Basic, Java, . . . has support for
lambda expressions or anonymous higher-order functions.
As with any idea that becomes mainstream, inevitably the underlying founda-
tions and principles get watered down or forgotten. Lisp allowed mutation, yet
today many confuse functions as first-class citizens with immutability. At the
same time, other effects such as exceptions, reflection, communication with the
outside world, and concurrency go unmentioned. Adding recursion in the form
of feedback-loops to pure combinational circuits lets us implement mutable state
via flip-flops. Similarly, using one effect such as concurrency or input/output we
can simulate other effects such as mutability. John Hughes famously stated in
his classic paper Why Functional Programming Matters that we cannot make
a language more powerful by eliminating features. To that, we add that often
we cannot even make a language less powerful by removing features. In this
book, Graham demonstrates convincingly that the true value of functional pro-
gramming lies in leveraging first-class functions to achieve compositionality and
equational reasoning. Or in Graham’s own words, “functional programming can
be viewed as a style of programming in which the basic method of computation
is the application of functions to arguments”. These functions do not necessarily
have to be pure or statically typed in order to realise the simplicity, elegance,
and conciseness of expression that we get from the functional style.
While you can code like a functional hacker in a plethora of languages, a
semantically pure and lazy, and syntactically lean and terse language such as
Haskell is still the best way to learn how to think like a fundamentalist. Based
upon decades of teaching experience, and backed by an impressive stream of re-
search papers, in this book Graham gently guides us through the whole gambit of
key functional programming concepts such as higher-order functions, recursion,
list comprehensions, algebraic datatypes and pattern matching. The book does
not shy away from more advanced concepts. If you are still confused by the n-th
blog post that attempts to explain monads, you are in the right place. Gently
starting with the IO monad, Graham progresses from functors to applicatives
using many concrete examples. By the time he arrives at monads, every reader
will feel that they themselves could have come up with the concept of a monad as
a generic pattern for composing functions with effects. The chapter on monadic
xiv Foreword

parsers brings everything together in a compelling use-case of parsing arithmetic


expressions in the implementation of a simple calculator.
This new edition not only adds many more concrete examples of concepts
introduced throughout the book, it also introduces the novel Haskell concepts of
foldable and traversable types. Readers familiar with object-oriented languages
routinely use iterables and visitors to enumerate over all values in a container,
or respectively to traverse complex data structures. Haskell’s higher-kinded type
classes allow for a very concise and abstract treatment of these concepts by means
of the Foldable and Traversable classes. Last but not least, the final chapters of
the book give an in-depth overview of lazy evaluation and equational reasoning
to prove and derive programs. The capstone chapter on calculating compilers
especially appeals to me because it touches a topic that has had my keen interest
for many decades, ever since my own PhD thesis on the same topic.
While there are plenty of alternative textbooks on Haskell in particular and
functional programming in general, Graham’s book is unique amongst all of these
in that it uses Haskell simply as a tool for thought, and never attempts to sell
Haskell or functional programming as a silver bullet that magically solves all
programming problems. It focuses on elegant and concise expression of intent
and thus makes a strong case of how pure and lazy functional programming is
an intelligible medium for efficiently reasoning about algorithms at a high level
of abstraction. The skills you acquire by studying this book will make you a
much better programmer no matter what language you use to actually program
in. In the past decade, using the first edition of this book I have taught many
tens of thousands of students how to juggle with code. With this new edition, I
am looking forward to extending this streak for at least another 10 years.

Erik Meijer
Preface

What is this book?


Haskell is a purely functional language that allows programmers to rapidly de-
velop software that is clear, concise and correct. The book is aimed at a broad
spectrum of readers who are interested in learning the language, including profes-
sional programmers, university students and high-school students. However, no
programming experience is required or assumed, and all concepts are explained
from first principles with the aid of carefully chosen examples and exercises. Most
of the material in the book should be accessible to anyone over the age of around
sixteen with a reasonable aptitude for scientific ideas.

How is it structured?
The book is divided into two parts. Part I introduces the basic concepts of pure
programming in Haskell and is structured around the core features of the lan-
guage, such as types, functions, list comprehensions, recursion and higher-order
functions. Part II covers impure programming and a range of more advanced
topics, such as monads, parsing, foldable types, lazy evaluation and reasoning
about programs. The book contains many extended programming examples, and
each chapter includes suggestions for further reading and a series of exercises.
The appendices provide solutions to selected exercises, and a summary of some
of the most commonly used definitions from the Haskell standard prelude.

What is its approach?


The book aims to teach the key concepts of Haskell in a clean and simple manner.
As this is a textbook rather than a reference manual we do not attempt to cover
all aspects of the language and its libraries, and we sometimes choose to define
functions from first principles rather than using library functions. As the book
progresses the level of generality that is used is gradually increased. For example,
in the beginning most of the functions that are used are specialised to simple
types, and later on we see how many functions can be generalised to larger classes
of types by exploiting particular features of Haskell.

How should it be read?


The basic material in part I can potentially be worked through fairly quickly,
particularly for those with some prior programming experience, but additional
time and effort may be required to absorb some of material in part II. Readers
are recommended to work through all the material in part I, and then select
xvi Preface

appropriate material from part II depending on their own interests. It is vital to


write Haskell code for yourself as you go along, as you can’t learn to program
just by reading. Try out the examples from each chapter as you proceed, and
solve the exercises for each chapter before checking the solutions.

What’s new in this edition?


The book is an extensively revised and expanded version of the first edition. It has
been extended with new chapters that cover more advanced aspects of Haskell,
new examples and exercises to further reinforce the concepts being introduced,
and solutions to selected exercises. The remaining material has been completely
reworked in response to changes in the language and feedback from readers. The
new edition uses the Glasgow Haskell Compiler (GHC), and is fully compati-
ble with the latest version of the language, including recent changes concerning
applicative, monadic, foldable and traversable types.

How can it be used for teaching?


An introductory course might cover all of part I and a few selected topics from
part II; my first-year course covers chapters 1–9, 10 and 15. An advanced course
might start with a refresher of part I, and cover a selection of more advanced
topics from part II; my second-year course focuses on chapters 12 and 16, and is
taught interactively on the board. The website for the book provides a range of
supporting materials, including PowerPoint slides and Haskell code for the ex-
tended examples. Instructors can obtain a large collection of exams and solutions
based on material in the book from solutions@cambridge.org.

Acknowledgements
I am grateful to the University of Nottingham for providing a sabbatical to pro-
duce this new edition; Thorsten Altenkirch, Venanzio Capretta, Henrik Nilsson
and other members of the FP lab for our many enjoyable discussions; Iván Pérez
Domı́nguez for useful comments on a number of chapters; the students and tutors
on all of my Haskell courses for their feedback; Clare Dennison, David Tranah
and Abigail Walkington at CUP for their editorial work; the GHC team for pro-
ducing such a great compiler; and finally, Catherine and Ian Hutton for getting
me started in computing all those years ago.
Many thanks also to Ki Yung Ahn, Bob Davison, Philip Hölzenspies and Neil
Mitchell for providing detailed comments on the first edition, and to the following
for pointing our errors and typos: Paul Brown, Sergio Queiroz de Medeiros,
David Duke, Robert Fabian, Ben Fleis, Robert Furber, Andrew Kish, Tomoyas
Kobayashi, Florian Larysch, Carlos Oroz, Douglas Philips, Bruce Turner, Gregor
Ulm, Marco Valtorta and Kazu Yamamoto. All of these comments have been
taken into account when preparing the new edition.

Graham Hutton
Part I
Basic Concepts
1 Introduction

In this chapter we set the stage for the rest of the book. We start by reviewing
the notion of a function, then introduce the concept of functional programming,
summarise the main features of Haskell and its historical background, and con-
clude with three small examples that give a taste of Haskell.

1.1 Functions

In Haskell, a function is a mapping that takes one or more arguments and pro-
duces a single result, and is defined using an equation that gives a name for the
function, a name for each of its arguments, and a body that specifies how the
result can be calculated in terms of the arguments.
For example, a function double that takes a number x as its argument, and
produces the result x + x, can be defined by the following equation:
double x = x + x
When a function is applied to actual arguments, the result is obtained by sub-
stituting these arguments into the body of the function in place of the argument
names. This process may immediately produce a result that cannot be further
simplified, such as a number. More commonly, however, the result will be an
expression containing other function applications, which must then be processed
in the same way to produce the final result.
For example, the result of the application double 3 of the function double to
the number 3 can be determined by the following calculation, in which each step
is explained by a short comment in curly parentheses:
double 3
“ t applying double u
3 + 3
“ t applying + u
6
Similarly, the result of the nested application double (double 2) in which the
function double is applied twice can be calculated as follows:
double (double 2)
4 Introduction

“ t applying the inner double u


double (2 + 2)
“ t applying + u
double 4
“ t applying double u
4 + 4
“ t applying + u
8

Alternatively, the same result can also be calculated by starting with the outer
application of the function double rather than the inner:

double (double 2)
“ t applying the outer double u
double 2 + double 2
“ t applying the first double u
(2 + 2) + double 2
“ t applying the first + u
4 + double 2
“ t applying double u
4 + (2 + 2)
“ t applying the second + u
4 + 4
“ t applying + u
8

However, this approach requires two more steps than our original version, because
the expression double 2 is duplicated in the first step and hence simplified twice.
In general, the order in which functions are applied in a calculation does not affect
the value of the final result, but it may affect the number of steps required, and
whether the calculation process terminates. These issues are explored in more
detail when we consider how expressions are evaluated in chapter 15.

1.2 Functional programming

What is functional programming? Opinions differ, and it is difficult to give a


precise definition. Generally speaking, however, functional programming can be
viewed as a style of programming in which the basic method of computation is
the application of functions to arguments. In turn, a functional programming
language is one that supports and encourages the functional style.
To illustrate these ideas, let us consider the task of computing the sum of the
integers (whole numbers) between one and some larger number n. In many cur-
rent programming languages, this would normally be achieved using two integer
variables whose values can be changed over time by means of the assignment
Discovering Diverse Content Through
Random Scribd Documents
The Project Gutenberg eBook of Original
stories from real life
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.

Title: Original stories from real life

Author: Mary Wollstonecraft

Release date: January 12, 2021 [eBook #64275]


Most recently updated: October 18, 2024

Language: English

Credits: Richard Tonsing and the Online Distributed Proofreading


Team at https://www.pgdp.net (This file was produced
from images generously made available by The
Internet Archive)

*** START OF THE PROJECT GUTENBERG EBOOK ORIGINAL


STORIES FROM REAL LIFE ***
Transcriber’s Note:
The cover image was created by the transcriber
and is placed in the public domain.
ORIGINAL STORIES
FROM

REAL LIFE;
WITH

CONVERSATIONS,
CALCULATED TO

REGULATE THE AFFECTIONS,


AND

FORM THE MIND TO TRUTH AND


GOODNESS.

BY

MARY WOLLSTONECRAFT.

A NEW EDITION.

LONDON:

PRINTED FOR J. JOHNSON, NO. 72, ST. PAUL’S CHURCH-YARD.

1796
PREFACE.

T hese conversations and tales are accommodated to the present


state of society; which obliges the author to attempt to cure those
faults by reason, which ought never to have taken root in the infant
mind. Good habits, imperceptibly fixed, are far preferable to the
precepts of reason; but, as this task requires more judgment than
generally falls to the lot of parents, substitutes must be sought for,
and medicines given, when regimen would have answered the
purpose much better. I believe those who examine their own minds
will readily agree with me, that reason, with difficulty, conquers
settled habits, even when it is arrived at some degree of maturity:
why then do we suffer children to be bound with fetters, which their
half-formed faculties cannot break.
In writing the following work, I aim at perspicuity and simplicity of
style; and try to avoid those unmeaning compliments, which slip
from the tongue, but have not the least connection with the
affections that should warm the heart, and animate the conduct. By
this false politeness, sincerity is sacrificed, and truth violated; and
thus artificial manners are necessarily taught. For true politeness is a
polish, not a varnish; and should rather be acquired by observation
than admonition. And we may remark, by way of illustration, that
men do not attempt to polish precious stones, till age and air have
given them that degree of solidity, which will enable them to bear the
necessary friction, without destroying the main substance.
The way to render instruction most useful cannot always be
adopted; knowledge should be gradually imparted, and flow more
from example than teaching: example directly addresses the senses,
the first inlets to the heart; and the improvement of those
instruments of the understanding is the object education should have
constantly in view, and over which we have most power. But to wish
that parents would, themselves, mould the ductile passions, is a
chimerical wish, for the present generation have their own passions
to combat with, and fastidious pleasures to pursue, neglecting those
pointed out by nature: we must therefore pour premature knowledge
into the succeeding one; and, teaching virtue, explain the nature of
vice. Cruel necessity!
The Conversations are intended to assist the teacher as well as the
pupil; and this will obviate an objection which some may start, that
the sentiments are not quite on a level with the capacity of a child.
Every child requires a different mode of treatment; but a writer can
only choose one, and that must be modified by those who are
actually engaged with young people in their studies.
The tendency of the reasoning obviously tends to fix principles of
truth and humanity on a solid and simple foundation; and to make
religion an active, invigorating director of the affections, and not a
mere attention to forms. Systems of Theology may be complicated;
but when the character of the Supreme Being is displayed, and He is
recognised as the Universal Father, the Author and Centre of Good, a
child may be led to comprehend that dignity and happiness must
arise from imitating Him; and this conviction should be twisted into,
and be the foundation of every inculcated duty.
At any rate, the Tales which were written to illustrate the moral,
may recall it, when the mind has gained sufficient strength to discuss
the argument from which it was deduced.
INTRODUCTION.

M ary and Caroline, though the children of wealthy parents were,


in their infancy, left entirely to the management of servants, or
people equally ignorant. Their mother died suddenly, and their
father, who found them very troublesome at home, placed them
under the tuition of a woman of tenderness and discernment, a near
relation, who was induced to take on herself the important charge
through motives of compassion.
They were shamefully ignorant, considering that Mary had been
fourteen, and Caroline twelve years in the world. If they had been
merely ignorant, the talk would not have appeared so arduous; but
they had caught every prejudice that the vulgar casually instill. In
order to eradicate these prejudices, and substitute good habits
instead of those they had carelessly contracted, Mrs. Mason never
suffered them to be out of her sight. They were allowed to ask
questions on all occasions, a method she would not have adopted,
had she educated them from the first, according to the suggestions of
her own reason, to which experience had given its sanction.
They had tolerable capacities; but Mary had a turn for ridicule, and
Caroline was vain of her person. She was, indeed, very handsome,
and the inconsiderate encomiums that had, in her presence, been
lavished on her beauty made her, even at that early age, affected.
CONTENTS.
C H A P . I.

The Treatment of Animals.—The Ant.—The Bee.—Goodness.—The


Lark’s Nest.—The Asses. Page 1

C H A P . II.

The Treatment of Animals.—The Difference between them and


Man.—The Parental Affection of a Dog.—Brutality punished. 10

C H A P . III.

The Treatment of Animals.—The Story of crazy Robin.—The Man


confined in the Bastille. 17

C H A P . IV.

Anger.—History of Jane Fretful. 25

C H A P . V.

Lying.—Honour.—Truth.—Small Duties.—History of Lady Sly and


Mrs. Trueman. 32

C H A P . VI.

Anger.—Folly produces Self-contempt, and the Neglect of others. 44

C H A P . VII.
Virtue the Soul of Beauty.—The Tulip and the Rose.—The
Nightingale.—External Ornaments.—Characters. 47

C H A P . VIII.

Summer Evening’s Amusement.—The Arrival of a Family of


Haymakers.—Ridicule of personal Defects censured.—A Storm.—
The Fear of Death.—The Cottage of Honest Jack the shipwrecked
Sailor.—The History of Jack, and his faithful Dog Pompey. 55

C H A P . IX.

The Inconveniences of immoderate Indulgence. 66

C H A P . X.

The Danger of Delay.—Description of a Mansion-House in Ruins.—


History of Charles Townley. 72

C H A P . XI.

Dress.—A Character.—Remarks on Mrs. Trueman’s Manner of


Dressing.—Trifling Omissions undermine Affection. 83

C H A P . XII.

Behaviour to Servants.—True Dignity of Character. 89

C H A P . XIII.

Employment.—Idleness produces Misery.—The Cultivation of the


Fancy raises us above the Vulgar, extends our Happiness, and
leads to Virtue. 93
C H A P . XIV.

Innocent Amusements.—Description of a Welch Castle.—History of


a Welch Harper.—A tyrannical Landlord.—Family Pride. 98

C H A P . XV.

Prayer.—A Moon-light Scene.—Resignation. 106

C H A P . XVI.

The Benefits arising from Devotion.—The History of the Village


School-mistress.—Fatal Effects of Inattention to Expences, in the
History of Mr. Lofty. 112

C H A P . XVII.

The Benefits arising from Devotion.—The History of the Village


School-mistress concluded. 119

C H A P . XVIII.

A Visit to the School-mistress.—True and False Pride. 122

C H A P . XIX.

Charity.—The History of Peggy and her Family.—The Sailor’s


Widow. 126

C H A P . XX.
Visit to Mrs. Trueman.—The Use of Accomplishments.—Virtue the
Soul of All. 131

C H A P . XXI.

The Benefit of bodily Pain.—Fortitude the Basis of Virtue.—The


Folly of Irresolution. 136

C H A P . XXII.

Journey to London. 141

C H A P . XXIII.

Charity.—Shopping.—The distressed stationer.—Mischievous


Consequences of delaying Payment. 143

C H A P . XXIV.

Visit to a Poor Family in London.—Idleness the Parent of Vice.—


Prodigality and Generosity incompatible.—The Pleasures of
Benevolence.—True and false Motives for Saving. 148

C H A P . XXV.

Mrs. Mason’s farewell Advice to her Pupils.—Observations on


Letter-writing. 153
MORAL CONVERSATIONS
AND

STORIES.

CHAP. I.
The Treatment of Animals.—The Ant.—The
Bee.—Goodness.—The Lark’s Nest.—The
Asses.

O ne fine morning in spring, some time after Mary and Caroline


were settled in their new abode, Mrs. Mason proposed a walk
before breakfast, a custom she wished to teach imperceptibly, by
rendering it amusing.
The sun had scarcely dispelled the dew that hung on every blade of
grass, and filled the half-shut flowers; every prospect smiled, and the
freshness of the air conveyed the most pleasing sensations to Mrs.
Mason’s mind; but the children were regardless of the surrounding
beauties, and ran eagerly after some insects to destroy them. Mrs.
Mason silently observed their cruel sports, without appearing to do
it; but stepping suddenly out of the foot-path into the long grass, her
buckle was caught in it, and striving to disentangle herself, she wet
her feet; which the children knew she wished to avoid, as she had
been lately sick. This circumstance roused their attention; and they
forgot their amusement to enquire why she had left the path; and
Mary could hardly restrain a laugh, when she was informed that it
was to avoid treading on some snails that were creeping across the
narrow footway. Surely, said Mary, you do not think there is any
harm in killing a snail, or any of those nasty creatures that crawl on
the ground? I hate them, and should scream if one was to find its way
from my clothes to my neck! With great gravity, Mrs. Mason asked
how she dared to kill any thing, unless it were to prevent its hurting
her? Then, resuming a smiling face, she said, Your education has
been neglected, my child; as we walk along attend to what I say, and
make the best answers you can; and do you, Caroline, join in the
conversation.
You have already heard that God created the world, and every
inhabitant of it. He is then called the Father of all creatures; and all
are made to be happy, whom a good and wise God has created. He
made those snails you despise, and caterpillars, and spiders; and
when he made them, did not leave them to perish, but placed them
where the food that is most proper to nourish them is easily found.
They do not live long, but He who is their Father, as well as your’s,
directs them to deposit their eggs on the plants that are fit to support
their young, when they are not able to get food for themselves.—And
when such a great and wise Being has taken care to provide every
thing necessary for the meanest creature, would you dare to kill it,
merely because it appears to you ugly? Mary began to be attentive,
and quickly followed Mrs. Mason’s example, who allowed a
caterpillar and a spider to creep on her hand. You find them, she
rejoined, very harmless; but a great number would destroy our
vegetables and fruit; so birds are permitted to eat them, as we feed
on animals; and in spring there are always more than at any other
season of the year, to furnish food for the young broods.—Half-
convinced, Mary said, But worms are of little consequence in the
world. Yet, replied Mrs. Mason, God cares for them, and gives them
every thing that is necessary to render their existence comfortable.
You are often troublesome—I am stronger than you—yet I do not kill
you.
Observe those ants; they have a little habitation in yonder hillock;
they carry food to it for their young, and sleep very snug in it during
the cold weather. The bees also have comfortable towns, and lay up a
store of honey to support them when the flowers die, and snow
covers the ground: and this forecast is as much the gift of God, as any
quality you possess.
Do you know the meaning of the word Goodness? I see you are
unwilling to answer. I will tell you. It is, first, to avoid hurting any
thing; and then, to contrive to give as much pleasure as you can. If
some insects are to be destroyed, to preserve my garden from
desolation, I have it done in the quickest way. The domestic animals
that I keep, I provide the best food for, and never suffer them to be
tormented; and this caution arises from two motives:—I wish to
make them happy; and, as I love my fellow-creatures still better than
the brute creation, I would not allow those that I have any influence
over to grow habitually thoughtless and cruel, till they were unable to
relish the greatest pleasure life affords,—that of resembling God, by
doing good.
A lark now began to sing, as it soared aloft. The children watched
its motions, listening to the artless melody. They wondered what it
was thinking of—of its young family, they soon concluded; for it flew
over the hedge, and drawing near, they heard the young ones chirp.
Very soon both the old birds took their flight together, to look for
food to satisfy the craving of the almost fledged young. An idle boy,
who had borrowed a gun, fired at them—they fell; and before he
could take up the wounded pair, he perceived Mrs. Mason; and
expecting a very severe reprimand, ran away. She and the little girls
drew near, and found that one was not much hurt, but that the other,
the cock, had one leg broken, and both its wings shattered; and its
little eyes seemed starting out of their sockets, it was in such
exquisite pain. The children turned away their eyes. Look at it, said
Mrs. Mason; do you not see that it suffers as much, and more than
you did when you had the small-pox, when you were so tenderly
nursed. Take up the hen; I will bind her wing together; perhaps it
may heal. As to the cock, though I hate to kill any thing, I must put
him out of pain; to leave him in his present state would be cruel; and
avoiding an unpleasant sensation myself, I should allow the poor
bird to die by inches, and call this treatment tenderness, when it
would be selfishness or weakness. Saying so, she put her foot on the
bird’s head, turning her own another way.
They walked on; when Caroline remarked, that the nestlings,
deprived of their parents, would now perish; and the mother began
to flutter in her hand as they drew near the hedge; though the poor
creature could not fly, yet she tried to do it. The girls, with one voice,
begged Mrs. Mason to let them take the nest, and provide food in a
cage, and see if the mother could not contrive to hop about to feed
them. The nest and the old mother were instantly in Mary’s
handkerchief. A little opening was left to admit the air; and Caroline
peeped into it every moment to see how they looked. I give you leave,
said Mrs. Mason, to take those birds, because an accident has
rendered them helpless; if that had not been the case, they should
not have been confined.
They had scarcely reached the next field, when they met another
boy with a nest in his hand, and on a tree near him saw the mother,
who, forgetting her natural timidity, followed the spoiler; and her
intelligible tones of anguish reached the ears of the children, whose
hearts now first felt the emotions of humanity. Caroline called him,
and taking sixpence out of her little purse, offered to give it to him
for the nest, if he would shew her where he had taken it from. The
boy consented, and away ran Caroline to replace it,—crying all the
way, how delighted the old bird will be to find her brood again. The
pleasure that the parent-bird would feel was talked of till they came
to a large common, and heard some young asses, at the door of an
hovel, making a most dreadful noise. Mrs. Mason had ordered the
old ones to be confined, lest the young should suck before the
necessary quantity had been saved for some sick people in her
neighbourhood. But after they had given the usual quantity of milk,
the thoughtless boy had left them still in confinement, and the young
in vain implored the food nature designed for their particular
support. Open the hatch, said Mrs. Mason, the mothers have still
enough left to satisfy their young. It was opened, and they saw them
suck.
Now, said she, we will return to breakfast; give me your hands, my
little girls, you have done good this morning, you have acted like
rational creatures. Look, what a fine morning it is. Insects, birds, and
animals, are all enjoying this sweet day. Thank God for permitting
you to see it, and for giving you an understanding which teaches you
that you ought, by doing good, to imitate Him. Other creatures only
think of supporting themselves; but man is allowed to ennoble his
nature, by cultivating his mind and enlarging his heart. He feels
disinterested love; every part of the creation affords an exercise for
virtue, and virtue is ever the truest source of pleasure.
CHAP. II
The Treatment of Animals.—The Difference
between them and Man.—Parental Affection
of a Dog.—Brutality punished.

A fter breakfast, Mrs. Mason gave the children Mrs. Trimmer’s


Fabulous Histories; and the subject still turned on animals, and
the wanton cruelty of those who treated them improperly. The little
girls were eager to express their detestation, and requested that in
future they might be allowed to feed the chickens. Mrs. Mason
complied with their request; only one condition was annexed to the
permission, that they did it regularly. When you wait for your food,
you learn patience, she added, and you can mention your wants; but
those helpless creatures cannot complain. The country people
frequently say,—How can you treat a poor dumb beast ill; and a
stress is very properly laid on the word dumb; for dumb they appear
to those who do not observe their looks and gestures; but God, who
takes care of every thing, understands their language; and so did
Caroline this morning, when she ran with such eagerness to replace
the nest which the thoughtless boy had stolen, heedless of the
mother’s agonizing cries!
Mary interrupted her, to ask, if insects and animals were not
inferior to men? Certainly, answered Mrs. Mason; and men are
inferior to angels; yet we have reason to believe, that those exalted
beings delight to do us good. You have heard in a book, which I
seldom permit you to read, because you are not of an age to
understand it, that angels, when they sang glory to God on high,
wished for peace on earth, as a proof of the good-will they felt
towards men. And all the glad tidings that have been sent to men,
angels have proclaimed: indeed, the word angel signifies a
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookfinal.com

You might also like