SlideShare a Scribd company logo
Functional Programming in C#: How to write
better C# code 1st Edition Enrico Buonanno
download
https://textbookfull.com/product/functional-programming-in-c-how-
to-write-better-c-code-1st-edition-enrico-buonanno/
Download more ebook from https://textbookfull.com
We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!
Functional Python Programming: Use a functional
approach to write succinct, expressive, and efficient
Python code, 3rd Edition Lott
https://textbookfull.com/product/functional-python-programming-
use-a-functional-approach-to-write-succinct-expressive-and-
efficient-python-code-3rd-edition-lott/
Effective C An introduction to professional C
programming 1st Edition Robert C. Seacord
https://textbookfull.com/product/effective-c-an-introduction-to-
professional-c-programming-1st-edition-robert-c-seacord/
Learn C++ by Example: Covers Versions 11 to 23 (Final
Release) 1 / converted Edition Frances Buontempo
https://textbookfull.com/product/learn-c-by-example-covers-
versions-11-to-23-final-release-1-converted-edition-frances-
buontempo/
Introduction to Programming with C 1st Edition Nhce
https://textbookfull.com/product/introduction-to-programming-
with-c-1st-edition-nhce/
Modern C++ for Absolute Beginners: A Friendly
Introduction to C++ Programming Language and C++11 to
C++20 Standards 1st Edition Slobodan Dmitrovi■
https://textbookfull.com/product/modern-c-for-absolute-beginners-
a-friendly-introduction-to-c-programming-language-
and-c11-to-c20-standards-1st-edition-slobodan-dmitrovic/
C Programming Complete Guide to Learn the Basics of C
Programming in 7 days 2nd Edition Xavier S Martin
https://textbookfull.com/product/c-programming-complete-guide-to-
learn-the-basics-of-c-programming-in-7-days-2nd-edition-xavier-s-
martin/
Functional Programming in JavaScript How to improve
your JavaScript programs using functional techniques
First Edition Luis Atencio
https://textbookfull.com/product/functional-programming-in-
javascript-how-to-improve-your-javascript-programs-using-
functional-techniques-first-edition-luis-atencio/
Functional Programming in JavaScript How to improve
your JavaScript programs using functional techniques 1
edition Edition Luis Atencio
https://textbookfull.com/product/functional-programming-in-
javascript-how-to-improve-your-javascript-programs-using-
functional-techniques-1-edition-edition-luis-atencio/
101 Challenges In C Programming 1st Edition Yashavant
Kanetkar
https://textbookfull.com/product/101-challenges-in-c-
programming-1st-edition-yashavant-kanetkar/
Functional Programming in C#: How to write better C# code 1st Edition Enrico Buonanno
Functional Programming in C#: How to
write better C# code
Enrico Buonanno
Copyright
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity. For
more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: orders@manning.com
©2018 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any
form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning Publications
was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to
have the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books are
printed on paper that is at least 15 percent recycled and processed without the use of elemental
chlorine.
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Development editor: Marina Michaels
Technical development editor: Joel Kotarski
Review editor: Aleksandar Dragosavljević
Project editor: Kevin Sullivan
Copyeditor: Andy Carroll
Proofreader: Melody Dolab
Technical proofreaders: Paul Louth, Jürgen Hoetzel
Typesetter: Gordan Salinovic
Cover designer: Leslie Haimes
Cartoons: Viseslav Radović,
Richard Sheppard
Graphic illustrations: Chuck Larson
ISBN 9781617293955
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – EBM – 22 21 20 19 18 17
Dedication
To the little monkey...
Brief Table of Contents
Copyright
Brief Table of Contents
Table of Contents
Preface
Acknowledgments
About this Book
1. Core concepts
Chapter 1. Introducing functional programming
Chapter 2. Why function purity matters
Chapter 3. Designing function signatures and types
Chapter 4. Patterns in functional programming
Chapter 5. Designing programs with function composition
2. Becoming functional
Chapter 6. Functional error handling
Chapter 7. Structuring an application with functions
Chapter 8. Working effectively with multi-argument functions
Chapter 9. Thinking about data functionally
Chapter 10. Event sourcing: a functional approach to persistence
3. Advanced techniques
Chapter 11. Lazy computations, continuations, and the beauty of monadic composition
Chapter 12. Stateful programs and stateful computations
Chapter 13. Working with asynchronous computations
Chapter 14. Data streams and the Reactive Extensions
Chapter 15. An introduction to message-passing concurrency
Epilogue: what next?
Inverted chapter dependency graph
The core functions of FP
Index
List of Figures
List of Tables
List of Listings
Table of Contents
Copyright
Brief Table of Contents
Table of Contents
Preface
Acknowledgments
About this Book
1. Core concepts
Chapter 1. Introducing functional programming
1.1. What is this thing called functional programming?
1.1.1. Functions as first-class values
1.1.2. Avoiding state mutation
1.1.3. Writing programs with strong guarantees
1.2. How functional a language is C#?
1.2.1. The functional nature of LINQ 1.2.2.
Functional features in C# 6 and C# 7 1.2.3.
A more functional future for C#?
1.3. Thinking in functions
1.3.1. Functions as maps
1.3.2. Representing functions in C#
1.4. Higher-order functions
1.4.1. Functions that depend on other functions
1.4.2. Adapter functions
1.4.3. Functions that create other functions
1.5. Using HOFs to avoid duplication
1.5.1. Encapsulating setup and teardown into a HOF
1.5.2. Turning the using statement into a HOF
1.5.3. Tradeoffs of HOFs
1.6. Benefits of functional programming
Exercises
Summary
Chapter 2. Why function purity matters
2.1. What is function purity?
2.1.1. Purity and side effects
2.1.2. Strategies for managing side effects
2.2. Purity and concurrency
2.2.1. Pure functions parallelize well
2.2.2. Parallelizing impure functions
2.2.3. Avoiding state mutation
2.3. Purity and testability
2.3.1. In practice: a validation scenario
2.3.2. Bringing impure functions under test
2.3.3. Why testing impure functions is hard
2.3.4. Parameterized unit tests
2.3.5. Avoiding header interfaces
2.4. Purity and the evolution of computing
Exercises
Summary
Chapter 3. Designing function signatures and types
3.1. Function signature design
3.1.1. Arrow notation
3.1.2. How informative is a
signature?3.2. Capturing data with data
objects
3.2.1. Primitive types are often not specific enough
3.2.2. Constraining inputs with custom types 3.2.3.
Writing “honest” functions
3.2.4. Composing values with tuples and objects
3.3. Modeling the absence of data with Unit
3.3.1. Why void isn’t ideal
3.3.2. Bridging the gap between Action and Func with Unit
3.4. Modeling the possible absence of data with Option
3.4.1. The bad APIs you use every day
3.4.2. An introduction to the Option type
3.4.3. Implementing Option
3.4.4. Gaining robustness by using Option instead of null
3.4.5. Option as the natural result type of partial functions
Exercises
Summary
Chapter 4. Patterns in functional programming
4.1. Applying a function to a structure’s inner values
4.1.1. Mapping a function onto a sequence 4.1.2.
Mapping a function onto an Option 4.1.3. How
Option raises the level of abstraction 4.1.4.
Introducing functors
4.2. Performing side effects with ForEach
4.3. Chaining functions with Bind
4.3.1. Combining Option-returning functions
4.3.2. Flattening nested lists with Bind 4.3.3.
Actually, it’s called a monad
4.3.4. The Return function
4.3.5. Relation between functors and monads 4.4.
Filtering values with Where
4.5. Combining Option and IEnumerable with Bind
4.6. Coding at different levels of abstraction
4.6.1. Regular vs. elevated values
4.6.2. Crossing levels of abstraction
4.6.3. Map vs. Bind, revisited
4.6.4. Working at the right level of abstraction
Exercises
Summary
Chapter 5. Designing programs with function composition
5.1. Function composition
5.1.1. Brushing up on function composition
5.1.2. Method chaining
5.1.3. Composition in the elevated world
5.2. Thinking in terms of data flow
5.2.1. Using LINQ’s composable API
5.2.2. Writing functions that compose well
5.3. Programming workflows
5.3.1. A simple workflow for validation
5.3.2. Refactoring with data flow in mind
5.3.3. Composition leads to greater flexibility
5.4. An introduction to functional domain modeling
5.5. An end-to-end server-side workflow
5.5.1. Expressions vs. statements
5.5.2. Declarative vs. imperative
5.5.3. The functional take on layering
Exercises
Summary
2. Becoming functional
Chapter 6. Functional error handling
6.1. A safer way to represent outcomes
6.1.1. Capturing error details with Either
6.1.2. Core functions for working with Either
6.1.3. Comparing Option and Either
6.2. Chaining operations that may fail 6.3.
Validation: a perfect use case for Either
6.3.1. Choosing a suitable representation for errors
6.3.2. Defining an Either-based API
6.3.3. Adding validation logic
6.4. Representing outcomes to client applications
6.4.1. Exposing an Option-like interface
6.4.2. Exposing an Either-like interface
6.4.3. Returning a result DTO
6.5. Variations on the Either theme
6.5.1. Changing between different error representations
6.5.2. Specialized versions of Either
6.5.3. Refactoring to Validation and Exceptional
6.5.4. Leaving exceptions behind?
Exercises
Summary
Chapter 7. Structuring an application with functions
7.1. Partial application: supplying arguments piecemeal
7.1.1. Manually enabling partial application
7.1.2. Generalizing partial application
7.1.3. Order of arguments matters
7.2. Overcoming the quirks of method resolution
7.3. Curried functions: optimized for partial application
7.4. Creating a partial-application-friendly API
7.4.1. Types as documentation
7.4.2. Particularizing the data access function
7.5. Modularizing and composing an application
7.5.1. Modularity in OOP
7.5.2. Modularity in FP
7.5.3. Comparing the two approaches
7.5.4. Composing the application
7.6. Reducing a list to a single value
7.6.1. LINQ’s Aggregate method
7.6.2. Aggregating validation results
7.6.3. Harvesting validation errors
Exercises
Summary
Chapter 8. Working effectively with multi-argument functions
8.1. Function application in the elevated world
8.1.1. Understanding applicatives
8.1.2. Lifting functions
8.1.3. An introduction to property-based testing
8.2. Functors, applicatives, monads
8.3. The monad laws
8.3.1. Right identity
8.3.2. Left identity
8.3.3. Associativity
8.3.4. Using Bind with multi-argument functions
8.4. Improving readability by using LINQ with any monad
8.4.1. Using LINQ with arbitrary functors
8.4.2. Using LINQ with arbitrary monads
8.4.3. let, where, and other LINQ clauses
8.5. When to use Bind vs. Apply
8.5.1. Validation with smart constructors
8.5.2. Harvesting errors with the applicative flow
8.5.3. Failing fast with the monadic flow
Exercises
Summary
Chapter 9. Thinking about data functionally
9.1. The pitfalls of state mutation
9.2. Understanding state, identity, and change
9.2.1. Some things never change
9.2.2. Representing change without mutation
9.3. Enforcing immutability
9.3.1. Immutable all the way down
9.3.2. Copy methods without boilerplate?
9.3.3. Leveraging F# for data types
9.3.4. Comparing strategies for immutability: an ugly contest
9.4. A short introduction to functional data structures
9.4.1. The classic functional linked list
9.4.2. Binary trees
Exercises
Summary
Chapter 10. Event sourcing: a functional approach to persistence
10.1. Thinking functionally about data storage
10.1.1. Why data storage should be append-only
10.1.2. Relax, and forget about storing state
10.2. Event sourcing basics
10.2.1. Representing events
10.2.2. Persisting events
10.2.3. Representing state
10.2.4. An interlude on pattern matching
10.2.5. Representing state transitions
10.2.6. Reconstructing the current state from past events
10.3. Architecture of an event-sourced system
10.3.1. Handling commands
10.3.2. Handling events
10.3.3. Adding validation
10.3.4. Creating views of the data from events
10.4. Comparing different approaches to immutable storage
10.4.1. Datomic vs. Event Store
10.4.2. How event-driven is your
domain?Summary
3. Advanced techniques
Chapter 11. Lazy computations, continuations, and the beauty of monadic composition
11.1. The virtue of laziness
11.1.1. Lazy APIs for working with Option
11.1.2. Composing lazy computations
11.2. Exception handling with Try
11.2.1. Representing computations that may fail
11.2.2. Safely extracting information from a JSON object
11.2.3. Composing computations that may fail
11.2.4. Monadic composition: what does it mean?
11.3. Creating a middleware pipeline for DB access
11.3.1. Composing functions that perform setup/teardown
11.3.2. A recipe against the pyramid of doom
11.3.3. Capturing the essence of a middleware function
11.3.4. Implementing the query pattern for middleware
11.3.5. Adding middleware that times the operation
11.3.6. Adding middleware that manages a DB transaction
Summary
Chapter 12. Stateful programs and stateful computations
12.1. Programs that manage state
12.1.1. Maintaining a cache of retrieved resources
12.1.2. Refactoring for testability and error handling
12.1.3. Stateful computations
12.2. A language for generating random data
12.2.1. Generating random integers
12.2.2. Generating other primitives
12.2.3. Generating complex structures
12.3. A general pattern for stateful computations
Summary
Chapter 13. Working with asynchronous computations
13.1. Asynchronous computations
13.1.1. The need for asynchrony
13.1.2. Representing asynchronous operations with Task
13.1.3. Task as a container for a future value
13.1.4. Handling failure
13.1.5. An HTTP API for currency conversion
13.1.6. If it fails, try a few more times
13.1.7. Running asynchronous operations in parallel
13.2. Traversables: working with lists of elevated values
13.2.1. Validating a list of values with monadic Traverse
13.2.2. Harvesting validation errors with applicative Traverse
13.2.3. Applying multiple validators to a single value 13.2.4.
Using Traverse with Task to await multiple results 13.2.5.
Defining Traverse for single-value structures
13.3. Combining asynchrony and validation (or any other two monadic effects)
13.3.1. The problem of stacked monads
13.3.2. Reducing the number of effects
13.3.3. LINQ expressions with a monad stack
Summary
Chapter 14. Data streams and the Reactive Extensions
14.1. Representing data streams with IObservable
14.1.1. A sequence of values in time
14.1.2. Subscribing to an IObservable
14.2. Creating IObservables
14.2.1. Creating a timer
14.2.2. Using Subject to tell an IObservable when it should signal
14.2.3. Creating IObservables from callback-based subscriptions
14.2.4. Creating IObservables from simpler structures
14.3. Transforming and combining data streams
14.3.1. Stream transformations
14.3.2. Combining and partitioning streams
14.3.3. Error handling with IObservable
14.3.4. Putting it all together
14.4. Implementing logic that spans multiple events
14.4.1. Detecting sequences of pressed keys
14.4.2. Reacting to multiple event sources
14.4.3. Notifying when an account becomes overdrawn
14.5. When should you use IObservable?
Summary
Chapter 15. An introduction to message-passing concurrency
15.1. The need for shared mutable state
15.2. Understanding message-passing concurrency
15.2.1. Implementing agents in C#
15.2.2. Getting started with agents
15.2.3. Using agents to handle concurrent requests
15.2.4. Agents vs. actors
15.3. Functional APIs, agent-based implementations
15.3.1. Agents as implementation details
15.3.2. Hiding agents behind a conventional API
15.4. Message-passing concurrency in LOB applications
15.4.1. Using an agent to synchronize access to account data
15.4.2. Keeping a registry of accounts
15.4.3. An agent is not an object
15.4.4. Putting it all together
Summary Epilogue:
what next?
Inverted chapter dependency graph
The core functions of FP
Index
List of Figures
List of Tables
List of Listings
Preface
Today, functional programming (FP) is no longer brooding in the research departments of
universities; it has become an important and exciting part of mainstream programming. The
majority of the languages and frameworks created in the last decade are functional, leading some
to predict that the future of programming is functional. Meanwhile, popular object-oriented
languages like C# and Java see the introduction of more functional features with every new
release, enabling a multiparadigm programming style.
And yet, adoption in the C# community has been slow. Why is this so? One reason, I believe, is
the lack of good literature:
Most FP literature is written in and for functional languages, especially Haskell. For
developers with a background in OOP, this poses a programming-language barrier to
learning the concepts. Even though many of the concepts apply to a multiparadigm
language like C#, learning a new paradigm and a new language at once is a tall order.
Even more importantly, most of the books in the literature tend to illustrate functional
techniques and concepts with examples from the domains of mathematics or computer
science. For the majority of programmers who work on line-of-business (LOB)
applications day in and day out, this creates a domain gap and leaves them wondering how
relevant these techniques may be for real-world applications.
These shortcomings posed major stumbling blocks in my own path to learning FP. After tossing
aside the n-th book that explained something known as currying by showing how the add
function can be curried with the number 3, creating a function that can add 3 to any number (can
you think of any application where this would be even remotely useful?), I decided to pursue my
own research path. This involved learning half a dozen functional languages (some better than
others), and seeing which concepts from FP could be effectively applied in C# and in the kind of
applications most developers are paid to write, and it culminated in the writing of this book.
This book bridges the language gap for C# developers by showing how you can leverage
functional techniques in this language. It also bridges the domain gap by showing how these
techniques can be applied to typical business scenarios. I take a pragmatic approach and cover
functional techniques to the extent that they’re useful in a typical LOB application scenario, and
dispense with most of the theory behind FP.
Ultimately, you should care about FP because it gives you the following:
Power— This simply means that you can get more done with less code. FP raises the level
of abstraction, allowing you to write high-level code while freeing you from low-level
technicalities that add complexity but no value.
Safety— This is especially true when dealing with concurrency. A program written in the
imperative style may work well in a single-threaded implementation but cause all sorts of
bugs when concurrency comes in. Functional code offers much better guarantees in
concurrent scenarios, so it’s only natural that we’re seeing a surge of interest in FP in the
era of multicore processors.
Clarity— We spend more time maintaining and consuming existing code than writing new
code, so it’s important that our code be clear and intention-revealing. As you learn to think
functionally, achieving this clarity will become more natural.
If you’ve been programming in an object-oriented style for some time, it may take a bit of effort
and willingness to experiment before the concepts in this book come to fruition. To make sure
learning FP is an enjoyable and rewarding process, I have two recommendations:
Be patient— You may have to read some sections more than once. You may put the book
down for a few weeks and find that when you pick it up again, something that seemed
obscure suddenly starts to make sense.
Experiment in code— You won’t learn unless you get your hands dirty. The book
provides many examples and exercises, and many of the code snippets can be tested in the
REPL.
Your colleagues may be less eager to explore than you. Expect them to protest your adoption of
this new style and to look perplexed at your code and say things like, “why not just do x?”
(where x is boring, obsolete, and usually harmful). Don’t discuss. Just sit back and watch them
eventually turn around and use your techniques to solve issues they run into again and again.
Acknowledgments
I’d like to thank Paul Louth, who not only provided inspiration through his LanguageExt library—
from which I borrowed many good ideas—but who also graciously reviewed the book at various
stages.
Manning’s thorough editorial process ensured that the quality of this book is infinitely better than
if I had been left to my own means. For this, I’d like to thank the team that collaborated on the
book, including Mike Stephens, development editor Marina Michaels, technical editor Joel
Kotarski, technical proofreader Jürgen Hoetzel, and copyeditor Andy Carroll.
Special thanks to Daniel Marbach and Tamir Dresher for their technical insights, as well as to all
those who took part in the peer reviews, including Alex Basile, Aurélien Gounot, Blair Leduc,
Chris Frank, Daniel Marbach, Devon Burriss, Gonzalo Barba López, Guy Smith, Kofi Sarfo,
Pauli Sutelainen, Russell Day, Tate Antrim, and Wayne Mather.
Thanks to Scott Wlaschin for sharing his articles at http://fsharpforfunandprofit.com, and to the
many other members of the FP community who share their knowledge and enthusiasm through
articles, blogs, and open source.
About this Book
This book aims to show how you can leverage functional techniques in C# to write code that is
concise, elegant, robust, and maintainable.
Who should read this book
This book is for an ambitious breed of developer. You know the C# language and the .NET
framework. You have experience developing real-world applications and are familiar with OOP
concepts, patterns, and best practices. Yet, you’re looking to expand your arsenal by learning
functional techniques so that you can make the most out of C# as a multiparadigm language.
If you’re trying or planning to learn a functional language, this book will also be hugely
valuable, because you’ll learn how to think functionally in a language you’re familiar with.
Changing the way you think is the hard part; once that’s achieved, learning the syntax of any
particular language will be relatively easy.
How this book is organized
The book consists of 15 chapters, divided into 3 parts:
Part 1 covers the basic techniques and principles of functional programming. We’ll start by
looking at what functional programming is and how C# supports programming in a
functional style. We’ll then look at the power of higher-order functions, function purity
and its relation to testability, the design of types and function signatures, and how simple
functions can be composed into complex programs. By the end of part 1, you’ll have a
good feel for what a program written in a functional style looks like and for the benefits
that this style has to offer.
With these basic concepts covered, we’ll pick up some speed in part 2 and move on to
wider-reaching concerns, such as functional error handling, modularizing and composing
an application, and the functional approach to understanding state and representing change.
By the end of part 2, you’ll have acquired a set of tools enabling you to effectively tackle
many programming tasks using a functional approach.
Part 3 will tackle more advanced topics, including lazy evaluation, stateful computations,
asynchrony, data streams, and concurrency. Each chapter in part 3 introduces important
techniques that have the potential to completely change the way you write and think about
software.
You’ll find a more detailed breakdown of the topics in each chapter, and a representation of what
chapters are required before reading any particular chapter, on the inside front cover page.
Coding for real-world applications
The book aims to stay true to real-world scenarios. To do this, many examples deal with practical
tasks such as reading configuration, connecting to a database, validating HTTP requests, and so
on—things you may already know how to do, but you’ll see them with the fresh perspective of
functional thinking.
Throughout the book, I use a long-running example to illustrate how FP can help when writing
LOB applications. For this, I’ve chosen an online banking application for the fictitious Bank of
Codeland (BOC)—naff, I know, but at least it has the obligatory three-letter acronym. Because
most people have access to an online banking facility, it should be easy to imagine the required
functionality and plain to see how the problems discussed are relevant to real-world applications.
I also use scenarios to illustrate how to solve typical programming problems in a functional style.
The constant back and forth between practical examples and FP concepts will hopefully help
bridge the gap between theory and practice—something I found wanting in the existing
literature, as I mentioned.
Leveraging functional libraries
A language like C# may have functional features, but to fully leverage these you’ll often use
libraries that facilitate common tasks. Microsoft has provided several libraries that facilitate
programming in a functional style, including these:
System.Linq—Yes, in case you didn’t know, it’s a functional library! I assume you’re
familiar with it, given that it’s such an important part of .NET.
System.Collections.Immutable—This is a library of immutable collections, which we’ll start
using in chapter 9.
System.Reactive—This is an implementation of the Reactive Extensions for .NET, allowing
you to work with data streams, which we’ll discuss in chapter 14.
This still leaves out plenty of other important types and functions that are staples of FP. As a
result, several independent developers have written libraries to fill those gaps. To date, the most
complete of these is LanguageExt, a library written by Paul Louth to improve the C# developer’s
experience when coding functionally.[1]
1
LanguageExt is open source and available on GitHub and NuGet:
https://github.com/louthy/language-ext.
In the book, I don’t use LanguageExt directly; instead, I’ll show you how I developed my own
library of functional utilities, called LaYumba.Functional, even though it largely overlaps with
LanguageExt. This is pedagogically more useful, for several reasons:
The code will remain stable after the book is published.
You get to look under the hood and see that powerful functional constructs are deceptively
simple to define.
You can concentrate on the essentials: I’ll show you the constructs in their purest form, so
that you won’t be distracted by the details and edge cases that a full-fledged library
addresses.
Code conventions and downloads
The code samples are in C# 7, and for the most part are compatible with C# 6. Language features
specifically introduced in C# 7 are only used in chapter 10 and beyond (and in a couple of
samples in section 1.2 that explicitly showcase C# 7).
You can execute many of the shorter snippets of code in a REPL, thereby gaining hands-on
practice with immediate feedback. The more extended examples are available for download at
https://github.com/la-yumba/functional-csharp-code, along with the exercises’ setup and
solutions.
Code listings in the book focus on the topic being discussed, and therefore may omit
namespaces, using statements, trivial constructors, or sections of code that appeared in a previous
listing and remain unchanged. If you’d like to see the full, compiling version of a listing, you’ll
find it in the code repository: https://github.com/la-yumba/functional-csharp-code.
Book forum
Purchase of Functional Programming in C# includes free access to a private web forum run by
Manning Publications where you can make comments about the book, ask technical questions,
and receive help from the author and from other users. To access the forum, go to
https://forums.manning.com/forums/functional-programming-in-c-sharp. You can also learn
more about Manning’s forums and the rules of conduct at
https://forums.manning.com/forums/about.
Manning’s commitment to our readers is to provide a venue where a meaningful dialogue
between individual readers and between readers and the author can take place. It is not a
commitment to any specific amount of participation on the part of the author, whose contribution
to the forum remains voluntary (and unpaid). We suggest you try asking the author some
challenging questions lest his interest stray! The forum and the archives of previous discussions
will be accessible from the publisher’s website as long as the book is in print.
About the author
Enrico Buonanno obtained an MS in Computer Science at Columbia University in 2001 and has
been working as a software developer and architect since. He’s worked on mission-critical
projects for prestigious companies in FinTech (including the Bank for International Settlements,
Barclays, and UBS) and other technology-driven businesses.
Part 1. Core concepts
In this part we’ll cover the basic techniques and principles of functional programming.
Chapter 1 starts by looking at what functional programming is, and how C# supports
programming in a functional style. It then delves deeper into higher-order functions, a
fundamental technique of FP.
Chapter 2 explains what pure functions are, why purity has important implications for a
function’s testability, and why pure functions lend themselves well to parallelization and other
optimizations.
Chapter 3 deals with principles for designing types and function signatures—things you thought
you knew but that receive a breath of fresh air when looked at from a functional perspective.
Chapter 4 introduces some of the core functions of FP: Map, Bind, ForEach, and Where (filter). These
functions provide the basic tools for interacting with the most common data structures in FP.
Chapter 5 shows how functions can be chained into pipelines that capture the workflows of your
program. It then widens the scope to developing a whole use case in a functional style.
By the end of part 1, you’ll have a good feel for what a program written in a functional style
looks like, and you’ll understand the benefits that this style has to offer.
Exploring the Variety of Random
Documents with Different Content
He had now taken to wearing an ‘inner sharp shirt of hair,’ and to
sleeping on the bare boards of his chamber, with a log under his
head for a pillow, and was otherwise schooling, by his powerful will,
his quick and buoyant nature into accordance with the strict rules of
the Carthusian brotherhood.[259]
It was a critical moment in his life. Soon after his father had been
imprisoned and fined, having some business with Fox, Bishop of
Winchester, that great courtier called him aside, pretending to be his
friend, and promised that if he would be ruled by him, he would not
fail to restore him into the King’s favour. But Fox was only setting a
trap for him, from which he was saved by a friendly hint from
Whitford,[260] the bishop’s chaplain. This man told More that his
master would not stick to agree to his own father’s death to serve
the King’s turn, and advised him to keep quite aloof from the King.
This hint was not reassuring, but it may have saved More’s life.
What would have happened to him had he been left alone with
misadvising friends to give hasty vent to the disappointment which
thus had crushed his hopes at the very outset of his career—whether
the cloister would have received him as it did his friend Whitford
afterwards, to be another ‘wretch of Sion,’ none can tell.
When
Colet
comes to
London,
More
chooses
him as his
spiritual
guide.
More’s
letter to
Colet.
More
alludes to
Colet’s
preaching
at St.
Paul’s.
Happily for him it was at this critical moment that Colet came up to
London to assume his new duties at St. Paul’s. More was a diligent
listener to his sermons, and chose him as his father confessor.
Stapleton has preserved a letter from More to Colet,[261] which
throws much light upon the relation between them. It was written in
October, 1504, whilst Colet, after preaching during the summer, was
apparently spending his long vacation in the country. It shows that,
under Colet’s advice, More was not altogether living the life of a
recluse.
Colet had for some time been absent from his pulpit at St. Paul’s. As
More was one day walking up and down Westminster Hall, waiting
while other people’s suits were being tried, he chanced to meet
Colet’s servant. Learning from him that his master had not yet
returned to town, More wrote to Colet this letter, to tell him how
much he missed his wonted delightful intercourse with him. He told
him how he had ever prized his most wise counsel; how by his most
delightful fellowship he had been refreshed; how by his weighty
sermons he had been roused, and by his example helped on his way.
He reminded him how fully he relied upon his guidance—how he had
been wont to hang upon his very beck and nod. Under his protection
he had felt himself gaining strength, now without it he was flagging
and undone. He acknowledged that, by following Colet’s leading, he
had escaped almost from the very jaws of hell; but now, amid all the
temptations of city life and the noisy wrangling of the law courts, he
felt himself losing ground without his help. No doubt the country
might be much more pleasant to Colet than the city, but the city,
with all its vice, and follies, and temptations, had far more need of
his skill than simple country folk! ‘There sometimes come, indeed,’
he added, ‘into the pulpit at St. Paul’s, men who promise to heal the
diseases of the people. But, though they seem to have preached
plausibly enough, their lives so jar with their words that they stir up
men’s wounds, rather than heal them.’ But, he said, his fellow-
citizens had confidence in Colet, and all longed for his return. He
urged him, therefore, to return speedily, for their sake and for his,
reminding Colet again that he had submitted himself in all things to
his guidance. ‘Meanwhile,’ he concluded, ‘I shall spend my time with
Grocyn, Linacre, and Lilly; the first, as you know, is the director of
my life in your absence; the second, the master of my studies; the
third, my most dear companion. Farewell, and, as you do, ever love
me.’
‘London: 10 Calend. Novembris’[1504].[262]
More
buries
himself in
his studies
with Lilly.
Surrounded as he was by Colet, Grocyn, and Linacre, More soon
began to devote his leisure to his old studies. Lilly, too, had returned
home well versed in Greek. He had spent some years in the island of
Rhodes, to perfect his knowledge of it.[263] Naturally enough,
therefore, the two friends busied themselves in jointly translating
Greek epigrams;[264] and as, with increasing zeal, they yielded to the
charms of the new learning, it is not surprising if the fascinations of
monastic life began to lose their hold upon their minds. The result
was that More was saved from the false step he once had
contemplated.
He had, it would seem, seen enough of the evil side of the ‘religious
life’ to know that in reality it did not offer that calm retreat from the
world which in theory it ought to have done. He had cautiously
abstained from rushing into vows before he had learned well what
they meant; and his experience of ascetic practices had far too
ruthlessly destroyed any pleasant pictures of monastic life in which
he may have indulged at first, to admit of his ever becoming a
Carthusian monk.
Still we may not doubt that, in truth, he had a real and natural
yearning for the pure ideal of cloister holiness. Early disappointed
love possibly,[265] added to the rude shipwreck made of his worldly
fortunes on the rock of royal displeasure, had, we may well believe,
effectually taught him the lesson not to trust in those ‘gay golden
dreams’ of worldly greatness, from which, he was often wont to say,
‘we cannot help awaking when we die;’ and even the penances and
scourgings inflicted by way of preparatory discipline upon his
‘wanton flesh,’ though soon proved to be of no great efficacy, were
not the less without some deep root in his nature; else why should
he wear secretly his whole life long the ‘sharp shirt of hair’ which we
hear about at last?[266]
So much as this must be conceded to More’s Catholic biographers,
who naturally incline to make the most of this ascetic phase of his
life.[267]
More
disgusted
with the
cloister.
But that, on the other hand, he did turn in disgust from the impurity
of the cloister to the better chances which, he thought, the world
offered of living a chaste and useful life, we know from Erasmus;
and this his Catholic biographers have, in their turn, acknowledged.
[268]
IV. MORE STUDIES PICO’S LIFE AND WORKS. HIS MARRIAGE
(1505).
More appears to have been influenced in the course he had taken,
mainly by two things:—first, a sort of hero-worship for the great
Italian, Pico della Mirandola; and, secondly, his continued reverence
for Colet.
More
translates
the life and
works of
Pico.
Pico’s
warm piety
and zeal.
A layman
to the end.
The ‘Life of Pico,’ with divers Epistles and other ‘Works’ of his, had
come into More’s hands. Very probably Lilly may have brought them
home with him amongst his Italian spoils. More had taken the pains
to translate them into English. He had doubtless heard all about
Pico’s outward life from those of his friends who had known him
personally when in Italy. But here was the record of Pico’s inner
history, for the most part in his own words; and reading this in
More’s translation, it is not hard to see how strong an influence it
may have exercised upon him. It told how, suddenly checked, as
More himself had been, in a career of worldly honour and ambition,
the proud vaunter of universal knowledge had been transformed into
the humble student of the Bible; how he had learned to abhor
scholastic disputations, of which he had been so great a master, and
to search for truth instead of fame. It told how, ‘giving no great
force to outward observances,’ ‘he cleaved to God in very fervent
love,’ so that, ‘on a time as he walked with his nephew in an orchard
at Ferrara, in talking of the love of Christ, he told him of his secret
purpose to give away his goods to the poor, and fencing himself with
the crucifix, barefoot, walking about the world, in every town and
castle to preach of Christ.’ It told how he, too, ‘scourged his own
flesh in remembrance of the passion and death that Christ suffered
for our sake;’ and urged others also ever to bear in mind two things,
‘that the Son of God died for thee, and that thou thyself shall die
shortly;’ and how, finally, in spite of the urgent warnings of the great
Savonarola, he remained a layman to the end, and in the midst of
indefatigable study of the Oriental languages, and, above all, the
Scriptures, through their means, died at the early age of thirty-five,
leaving the world to wonder at his genius, and Savonarola to preach
a sermon on his death.[269]
The Works
of Pico.
And turning from the ‘Life of Pico’ to his ‘Works,’ and reading these
in More’s translation, they present to the mind a type of Christianity,
so opposite to the ceremonial and external religion of the monks,
that one may well cease to wonder that More, having caught the
spirit of Pico’s religion, could no longer entertain any notion of
becoming a Carthusian brother.
It will be worth while to examine carefully what these works of Pico’s
were.
Pico’s
letter to
his
nephew.
The first is a letter from Pico to his nephew—a letter of advice to a
young man somewhat in More’s position, longing to live to some
‘virtuous purpose,’ but finding it hard to stem the tide of evil around
him. To encourage his nephew, he speaks of the ‘great peace and
felicity it is to the mind when a man hath nothing that grudgeth his
conscience, nor is appalled with the secret touch of any privy
crime.’... ‘Doubtest thou, my son, whether the minds of wicked men
be vexed or not with continual thought and torment?... The wicked
man’s heart is like the stormy sea, that may not rest. There is to him
nothing sure, nothing peaceable, but all things fearful, all things
sorrowful, all things deadly. Shall we, then, envy these men? Shall
we follow them, forgetting our own country—heaven, and our own
heavenly Father—where we were free-born? Shall we wilfully make
ourselves bondmen, and with them, wretched living, more
wretchedly die, and at the last most wretchedly in everlasting fire be
punished?’
Pico’s faith
in
Christianity
.
Having warned his nephew against wicked companions, Pico
proceeds to make evident allusion to the sceptical tendencies of
Italian society. ‘It is verily a great madness’ (he says) ‘not to believe
the Gospel, whose truth the blood of martyrs crieth, the voice of
Apostles soundeth, miracles prove, reason confirmeth, the world
testifieth, the elements speak, devils confess!’[270] ‘But,’ he
continues, ‘a far greater madness is it, if thou doubt not but that the
Gospel is true, to live then as though thou doubtest not but that it
were false.’
Its
reasonable
ness and
harmony
with the
laws of
nature.
Pico on
prayer.
Pico on the
Scriptures.
And it is worth notice, that the perception of the reasonableness of
Christianity, and its harmony with the laws of nature, breaks out
again a little further on. Pico writes to his nephew: ‘Take no heed
what thing many men do, but [take heed] what thing the very law of
nature, what thing very reason, what thing our Lord himself showeth
thee to be done.’
A little further on Pico points out two remedies, or aids, whereby his
nephew may be strengthened in his course. First, charity; and
secondly, prayer. With regard to the first he wrote:—‘Certainly He
shall not hear thee when thou callest on Him, if thou hear not first
the poor man when he calleth upon thee.’ With regard to prayer, he
wrote thus:—‘When I stir thee to prayer, I stir thee not to the prayer
that standeth in many words, but to that prayer which, in the secret
chamber of the mind, in the privy-closet of the soul, with very affect
speaketh unto God, and in the most lightsome darkness of
contemplation, not only presenteth the mind to the Father, but also
uniteth it with Him by unspeakable ways, which only they know that
have assayed. Nor I care not how long or how short thy prayer be,
but how effectual, how ardent.... Let no day pass, then, but thou
once at the leastwise present thyself to God by prayer, and falling
down before Him flat to the ground, with an humble affect of devout
mind, not from the extremity of thy lips, but out of the inwardness of
thine heart, cry these words of the prophet: “The offences of my
youth, and mine ignorances, remember not, good Lord, but after thy
goodness remember me.” What thou shalt in thy prayer ask of God,
both the Holy Spirit, which prayeth for us and eke thine own
necessity, shall every hour put into thy mind, and also what thou
shalt pray for thou shalt find matter enough in the reading of Holy
Scripture, which that thou wouldst now (setting poets, fables, and
trifles aside) take ever in thine hand I heartily pray thee; ... there
lieth in them a certain heavenly strength quick and effectual, which
with marvellous power transformeth and changeth the readers’ mind
into the love of God, if they be clean and lowly entreated.’ Lastly, he
said he would ‘make an end with this one thing. I warn thee (of
which when we were last together I often talked with thee) that
thou never forget these two things; that both the Son of God died
for thee, and that thou thyself shalt die shortly!’[271]
This, then, was the doctrine which Pico, ‘fencing himself with a
crucifix, barefoot, walking about the world, in every town and castle,’
purposed to preach!
The next letter is a reply to a friend of his who had urged him to
leave his contemplative and studious life, and to mix in political
affairs, in which, as an Italian prince, lay his natural sphere. He
replied, that his desire was ‘not so to embrace Martha as utterly to
forsake Mary’—to ‘love them and use them both, as well study as
worldly occupation.’ ‘I set more’ (he continued) ‘by my little house,
my study, the pleasure of my books, the rest and peace of my mind,
than by all your king’s palaces, all your business, all your glory, all
the advantage that ye hawke after, and all the favour of the court!’
Pico’s
study of
Eastern
languages.
Then he tells his friend that what he looks to do is, ‘to give out some
books of mine to the common profit,’ and that he is mastering the
Hebrew, Chaldee, and Arabic languages.[272]
Another
letter to
his
nephew.
Then follows another letter to his nephew, who, in trying to follow
the advice given in his first letter, finds himself slandered and called
a hypocrite by his companions at court. It is a letter of noble
encouragement to stand his ground, and to heed not the scoffs and
sneers of his fellows.
These letters are followed by an exposition of Psalm xvi., in which
Pico incidentally uses his knowledge of the Hebrew text and of
Eastern customs.[273]
Pico’s
verses.
All the foregoing are in prose; after them come More’s translations of
some of Pico’s verses.
The first is entitled, ‘Twelve rules, partly exciting and partly directing
a man in spiritual battle,’ and reminds one of the ‘Enchiridion’ of
Erasmus. The second is named, ‘The twelve weapons of spiritual
battle.’ The striking feature in both these metrical works is the
holding up of Christ’s example as an incentive to duty and to love.
Thus:—
‘Consider, when thou art movèd to be wroth,
He who that was God and of all men the best,
Seeing himself scorned and scourgèd both,
And as a thief between two thievès threst,
With all rebuke and shame; yet from his breast
Came never sign of wrath or of disdain,
But patiently endurèd all the pain!’
And again, after speaking of the shortness of life—
‘How fast it runneth on, and passen shall
As doth a dream or shadow on a wall.’
he continues:—
‘Think on the very lamentable pain,
Think on the piteous cross of woeful Christ,
Think on his blood, beat out at every vein,
Think on his precious heart carvèd in twain:
Think how for thy redemption all was wrought.
Let him not lose, what he so dear hath bought.’
There is another poem in which the feelings of a lover towards his
love are made to show what the Christian’s feelings ought to be to
Christ; and lastly, there is a solemn and beautiful ‘Prayer of Picus
Mirandola to God,’ glowing with the same adoration of
... ‘that mighty love
Which able was thy dreadful majesty
To draw down into earth from heaven above
And crucify God, that we poor wretches, we
Should from our filthy sin yclensèd be!’
and the same earnest longing
‘That when the journey of this deadly life
My silly ghost hath finished, and thence
Departen must,’ ...
‘He may Thee find ...
In thy lordship, not as a lord, but rather
As a very tender, loving father!’
Pico’s
enlightene
d piety.
I have made these quotations, and thus endeavoured to put the
reader in possession of the contents of this little volume, which More
in his seclusion was translating, because I think they throw some
light upon the current in which his thoughts were moving, and
because, whilst the name of Pico is known to fame as that of a great
linguist and most precocious genius, his enlightened piety and the
extent of the influence of his heroic example have scarcely been
appreciated.
This little book, indeed, has a special significance in relation to the
history of the Oxford Reformers. Whatever doubt may rest upon the
direct connection between their views and those of Savonarola,
there is here in More’s translation of these writings of a disciple of
Savonarola, another indirect connection between them and that little
knot of earnest Christian men in Italy of which Savonarola was the
most conspicuous.
Position of
the Neo-
Platonic
philosophe
rs of
Florence.
The extracts made and translated by More from Pico’s writings may
also help us to recognise in the Neo-Platonic philosophers of
Florence, by whose writings Colet had been so profoundly
influenced, a vein of earnest Christian feeling of which it may be that
we know too little. Like their predecessors of a thousand years
before, they stood between the old world and the new. They were
the men who, when the learning of the old Pagan world was
restored to light, and backed against the dogmatic creed of priest-
ridden degraded Christendom, built a bridge, as it were, between
Christian and Pagan thought. That their bridge was frail and insecure
it may be, but, to a great extent, it served its end. A passage was
effected by it from the Pagan to the Christian shore. Ficino, the
representative Neo-Platonist, who, as has been seen, had aided in its
building, had himself passed over it. Savonarola too had crossed it.
Pico had crossed it. It is true that these men may, to some extent,
have Platonised Christianity in becoming Christian; but it will be
recognised at once that the earnest Christian feeling found by More
in Pico, so to speak, rose far above his Platonism.
More calls
Savonarola
a ‘man of
God.’
That the life and writings of such a man should have awakened in
his breast something of hero-worship[274] is, therefore, not
surprising. That he should have singled out these passages, and
taken the trouble to translate them, is some proof that he admired
Pico’s practical piety more than his Neo-Platonic speculations; that
he shared with Colet those yearnings for practical Christian reform
with which Colet had returned from Italy ten years before. That a
few years after this translation should be published and issued in
English in More’s name was further proof of it. For here was a book
not only in its drift and spirit boldly taking Cole’s side against the
Schoolmen, and in favour of the study of Scripture and the Oriental
languages, but as boldly holding up Savonarola as ‘a preacher, as
well in cunning as in holiness of living, most famous,’—‘a holy
man’—‘a man of God’[275]—in the teeth of the fact that he had been
denounced by the Pope as a ‘son of blasphemy and perdition,’
excommunicated, tortured, and, refusing to abjure, hung and burned
as a heretic![276]
Colet’s
influence
on More.
And if the fire of hero-worship for Pico had lit up something of
heroism in More’s heart—something which yearned for the battle of
life, and not for the rest of the cloister—so the living example of
Colet was ready to feed the flame into strength and steadiness.
More
marries
under
Colet’s
advice.
The result was that, in 1505,[277] in spite of early disappointments,
and, it is said, under Colet’s ‘advice and direction,’[278] More married
Jane Colt, of New Hall in Essex, took a house in Bucklersbury, and
gave up for ever all longings for monastic life.
V. HOW IT HAD FARED WITH ERASMUS (1500-5).
Soon after Colet’s elevation to the dignities of Doctor and Dean, a
letter of congratulation arrived from Erasmus.
Colet had written no letter to him, and had almost lost sight of him
during these years. It would seem that, after his departure from
Oxford, Colet had given up all hopes of his aid. Nor had any other
kindred soul risen up to take that place in fellow-work beside him,
which at one time he had hoped the great scholar might have filled.
Erasmus
had not
forgotten
Colet.
The legal
robbery of
Erasmus at
Dover.
But Erasmus on his side had not forgotten Colet. His intercourse with
Colet at Oxford had changed the current of his thoughts, and the
course of his life. Colet little knew by what slow and painful steps he
had been preparing to redeem the promise he had made on leaving
Oxford.
We left him making the best of his way to Dover, with his purse full
of golden crowns, kindly bestowed by his English friends in order
that he might now carry out his long-cherished intention of going to
Italy. But the Fates had decreed against him. King Henry VII. had
already reached the avaricious period of his life and reign. Under
cover of an old obsolete statute, he had given orders to the Custom
House officers to stop the exportation of all precious metals, and the
Custom House officers in their turn, construing their instructions
strictly to the letter, had seized upon Erasmus’s purseful of golden
crowns, and relieved him of the burden, for the benefit of the King’s
exchequer.[279] The poor scholar proceeded without them to cross to
Boulogne.
He was a bad sailor, and the hardships of travel soon told upon his
health. He was heart-sick also; as well he might be, for this unlucky
loss of his purse had utterly disconcerted once more his long-
cherished plans. On his arrival at Paris, after a wretched and
dangerous journey,[280] he was taken ill, and recovered only to bear
his bitter disappointment as best he could. Before he had yet
recovered from his illness he wrote this touching letter to Arnold, the
young legal friend of More, with whom a few weeks before he and
More had visited the Royal nursery.
Erasmus to Arnold.[281]
Erasmus
gives up all
hope of
going to
Italy.
‘Salve, mi Arnolde. Now for six weeks I having been
suffering much from a nocturnal ague, of a lingering kind
but of daily recurrence, and it has nearly killed me. I am
not yet free from the disease, but still somewhat better. I
don’t yet live again, but some hope of life dawns upon
me. You ask me to tell you my plans. Take this only, to
begin with: To mortify myself to the world, I dash my
hopes. I long for nothing more than to give myself rest, in
which I might live wholly to God alone, weep away the
sins of a careless life, devote myself to the study of the
Holy Scriptures, either read somewhat or write. This I
cannot do in a monastery or college. One could not be
more delicate than I am; my health will bear neither vigils,
nor fasts, nor any disturbance, even when at its best.
Here, where I live in such luxury, I often fall ill; what
should I do amid the labours of college life?
Cost of
going to
Italy.
‘I had determined to go to Italy this year, and to work at
theology some months at Bologna; also there to take the
degree of Doctor; then in the year of Jubilee to visit
Rome; which done, to return to my friends and then to
settle down. But I am afraid that these things that I
would, I shall not be able to accomplish. I fear, in the first
place, that my health would not stand such a journey and
the heat of the climate. Lastly, I reckon that I could not go
to Italy, nor live there without great expense. It costs a
great deal also to prepare for a degree. And the Bishop of
Cambray gives very sparingly. He altogether loves more
liberally than he gives, and promises everything much
more largely than he performs. It is partly my own fault
for not pressing him. There are so many who are even
extorting. In the meantime I shall do what seems for the
best. Farewell.’
What was he to do? It was clear that he did not know what to do.
The worst of it was that the unfortunate loss of the price of many
months’ leisure,[282] not only obliged him to postpone sine die his
project of visiting Italy, but also to spend a large portion of his time
and strength for the next few years in a struggle almost for
subsistence. For the wolf must in some way or other be kept from
the door; and Erasmus was poor!
Poverty of
Erasmus.
His Greek
studies.
Erasmus
visits
Holland.
For a few months he struggled on at Paris, living in lodgings with an
old fellow student ‘sparingly,’[283] hard at work at a collection of
Greek and Latin proverbs—his Adagia—partly in order to raise the
wind, partly to improve himself in Greek. Sometimes borrowing and
sometimes begging, whatever money came to his hands went
forthwith first in buying Greek books and then in clothes.[284] Later
in the year, the prevalence of the Plague in Paris drove him to
Orleans. He would have gone to Italy, but he had not the means.
[285] In December he returned to Paris to continue his struggling life.
[286] In a letter written in January, 1501, on the anniversary of his
misfortune at Dover, he described himself ‘as having now for a whole
year been sailing under a stormy sky against the waves and against
the winds.’[287] To add to his troubles, the Plague again broke out in
Paris; and, terrified by the number of funerals passing his door, the
poor scholar fled from the city to spend a few weeks in his native
country.[288] During his stay in Holland he visited the monastery at
Stein,[289] where in early years he had tasted the bitters of the
monastic life. Neither there nor elsewhere in Holland did he find a
resting-place.
Princess of
Vere and
Battus.
Fortunately for him, one true friend at least turned up, willing and
able to enter into sympathy with him. This was Battus, tutor to the
Marchioness of Vere. Erasmus had already corresponded with him
from Paris, pouring out his troubles to him, and declaring that he
had no other hope but in him alone.[290] Kept away from Paris by the
Plague, and finding not even a temporary home in Holland, he at
last found a refuge for a while from his fears and cares in a visit to
the castle of Tornahens,[291] the residence of the Marchioness of
Vere and of Battus. It had the additional attraction of being near to
St. Omer, where lived a former patron of Erasmus, the Abbot of St.
Bertin.
Erasmus
would like
to visit
Colet
again.
Whilst staying with Battus he wrote to a friend, that he sometimes
thought of returning to England to spend a month or two more with
Colet, in order to confer further with him on some theological
questions. He knew well, he said, how much good he should gain
from doing so, but he could not get over the unlucky experience of
his last voyage. As to his journey to Italy, that, too, was knocked on
the head. He told his friend that he longed to visit Italy as ardently
as ever, but it was out of the question; for, according to the adage of
Plautus, ‘Sine pennis volare haud facile est.’[292]
Writes his
‘Enchiridio
n.’
Battus also wrote to Lord Mountjoy to tell him with what pleasure he
had embraced Erasmus, but, ‘alas, how ill-treated and spoiled!’ He
told him how he had been commiserating Erasmus on his ill-fortune
in England, and how the philosopher had smiled and bade him put a
good face on it, He did not regret having visited England; he cared
more for the friends he had found in England than for all the gold of
Crœsus. Battus concluded by telling Lord Mountjoy how Erasmus
had described to him the courtesy of the Prior Charnock, the
learning of Colet, the good nature of More, the virtues of his noble
patron.[293] It was during this visit to St. Omer, in the summer of
1501, that Erasmus wrote his ‘Enchiridion.’
There happened to be staying in the castle a lady, a friend of Battus,
who had a bad husband. The latter, whilst holding other divines at
arm’s length, took to Erasmus. The wife, thinking that he possibly
might have some influence over her husband, begged him, without
betraying that it was at her instigation, to write something which
might produce in him some religious impressions.[294] The
‘Enchiridion’ was the result, of which more will be said by and by.
John
Vitrarius.
It was at St. Omer also that Erasmus became acquainted with John
Vitrarius—a second John Colet in the earnestness of his Christian
zeal against the corruptions of the church and vices of the clergy, in
his love for St. Paul, in his outspoken preaching, and even in his
manner of preaching, in his dislike of the Scholastic subtlety of
Scotus, and even in his preference for Ambrose, Cyprian, Jerome,
and Origen over Augustine. Erasmus ever afterwards linked the
names of Colet and Vitrarius together, and admitted them both
deservedly into his calendar of uncanonised saints.[295] The
‘Enchiridion’ was submitted to the judgment of Vitrarius, and
obtained his approval.[296]
Return of
Erasmus to
Paris.
After many refreshing days passed at St. Omer, Erasmus returned to
Paris to pursue his literary labours. These, notwithstanding all the
hindrances of ill-health and poverty, never seemed to have flagged.
[297] He had already made up his mind to devote himself to the
Herculean task of correcting the text of St. Jerome’s voluminous
works, with a view to their publication.[298] The first edition of his
‘Adagia’ had been printed in 1501; and during a visit to Louvain and
Antwerp, in 1503, he was able to publish some other works—his
afterwards famous ‘Enchiridion’ amongst the rest.[299] But
notwithstanding all his indomitable energy, and the often repeated
kindness of Battus and the Marchioness, it would be difficult to
imagine a longer catalogue of troubles and disappointments—and
these too of that harassing and vexatious kind which are most trying
to the temper—than is contained in the letters of Erasmus during
these dreary years.[300]
He might well have been excused if, lost sight of as it would seem by
his English friends, he had himself forgotten his promise to Colet on
leaving Oxford, amidst the cares of his continental life.
Erasmus
remembers
his
promise to
Colet.
But whilst these necessities not a little interrupted, as was likely,
those studies to which Colet’s example and precept had urged him,
and lengthened out the preliminary labours which Erasmus had
made up his mind must precede his active participation in Colet’s
work, they did not, it seems, damp his energy, or induce him to look
back after putting his hand to the plough. This and more lies
touchingly hinted in the following letter written by Erasmus to Colet
on receipt of the news of the elevation of his friend to the dignity of
Doctor and Dean.
Erasmus to Colet.[301]
‘If our friendship, most learned Colet, had been of a
common-place kind, or your habits those of the common
run of men, I should indeed have been somewhat fearful
lest it might have been extinguished, or at least cooled, by
our long and wide separation.... But I prefer to believe
that the cause of my having received no letter from you
now for several years, lies rather in your press of
business, or ignorance of my whereabouts, or even in
myself, than in your forgetfulness of an old friend....
‘I am much surprised that you have not yet given to the
world any of your commentaries on St. Paul and the
Gospels. I know your modesty, but surely you ought to
conquer that, and print them for the public good.
Erasmus
congratulat
es Colet on
his
preferment
.
Wants to
devote
himself to
Scripture
studies.
Greek and
Hebrew
studies.
‘As to the title of Doctor and Dean, I do not so much
congratulate you about these—for I know well they will
bring you nothing but labour—as those for whose good
you are to bear them.
‘I cannot tell you, dearest Colet, how, by hook and by
crook, I struggle to devote myself to the study of sacred
literature—how I regret everything which either delays me
or detains me from it. But constant ill-fortune has
prevented me from extricating myself from these
hindrances. When in France, I determined that if I could
not conquer these difficulties I would cast them aside, and
that once freed from them, with my whole mind I would
set to work at these sacred studies, and devote the rest of
my life to them. Although three years before I had
attempted something on St. Paul’s Epistle to the Romans,
[302] and had completed four volumes at one pull, I was
nevertheless prevented from going on with it, owing
chiefly to the want of a better knowledge of Greek.
Consequently, for nearly these three years past, I have
buried myself in Greek literature; nor do I think the labour
has been thrown away. I began also to dip into Hebrew,
but, deterred by the strangeness of the words, I desisted,
knowing that one man’s life and genius are not enough for
too many things at a time. I have read through a good
part of the works of Origen, under whose guidance I
seemed really to get on, for he opened to me, as it were,
the springs and the method of theological science.
The
‘Enchiridio
n.’
‘I send you [herewith], as a little literary present, some
lucubrations of mine. Among them is our discussion, when
in England, on the Agony of Christ, but so altered that you
will hardly know it again. Besides, your reply and my
rejoinder to it could not be found. The “Enchiridion” I
wrote to display neither genius nor eloquence, but simply
for this—to counteract the vulgar error of those who think
that religion consists in ceremonies, and in more than
Jewish observances, while they neglect what really
pertains to piety. I have tried to teach, as it were, the art
of piety in the same way as others have laid down the
rules of [military] discipline.... The rest were written
against the grain, especially the “Pæan” and “Obsecratio,”
which I wrote to please Battus and Anna, the Princess of
Vere. As to the “Panegyric,”[303] it was so contrary to my
taste, that I do not remember ever having written
anything more reluctantly; for I saw that such a thing
could not be done without adulation....
The
‘Adagia.’
Erasmus
wants help
from his
friends.
‘I wrote, if you recollect, sometime past, about the 100
copies of the “Adagia” which I sent at my own expense
into England, now three years ago. Grocyn wrote me word
that he would arrange with the greatest fidelity and
diligence that they should be sold according to my wish,
and I do not doubt but that he has performed his promise,
for he is the best and most honourable man that ever
lived in England. Will you be so good as to aid me in this
matter, so far as to advise and spur on those by whom
you think the business ought to be settled? For one
cannot doubt but that, in so long a time, the books must
be sold; and the money must of necessity have come to
somebody’s hand; and it is likely to be of more use to me
now than ever before. For, by some means or other, I
must contrive to have a few months entirely to myself,
that I may extricate myself somehow from my labours in
secular literature. This I trusted I could have done this
winter, had not so many hopes proved illusive. Nor,
indeed, “with a great sum can I obtain this freedom,” even
for a few months. I entreat you, therefore, to do what you
can to aid me, panting as I do eagerly after sacred
studies, in disengaging myself from those [secular] studies
which have now ceased to be pleasant to me. It would not
do for me to beg of my friend, Lord Mountjoy, although it
would not seem unreasonable or impertinent if, of his own
good will, he had chosen to aid me, both on the ground of
his habitual patronage of my studies, and also because
the “Adagia” were undertaken at his suggestion, and
inscribed with his name. I am ashamed of the first edition
[of the “Adagia”] both on account of the blundering
mistakes of the printers, which seem made almost on
purpose, and because, urged on by others, I hurried over
the work which had now begun to seem to me dry and
poor after my study of the Greek authors. Consequently,
another edition is resolved upon, in which the errors of
both author and printer are to be corrected, and the work
made as useful as possible to students.
His Greek
studies not
thrown
away.
‘Although, however, I may for a while be engaged upon an
humble task, yet whilst thus working in the Garden of the
Greeks, I am gathering much fruit by the way for the time
to come, which may hereafter be of use to me in sacred
studies. For I have learned this by experience, that
without Greek one can do nothing in any branch of study;
for it is one thing to conjecture, and quite another thing to
judge—one thing to see with other people’s eyes, and
quite another thing to believe what you see with your
own.
‘But to what a length this letter has grown! Love, however,
will excuse loquacity. Farewell, most learned and excellent
Colet.
‘Pray let me know what has happened to our friend
Sixtinus; also what your friend the Prior Richard Charnock
is doing.
‘In order that whatever you may write or send to me may
duly come to hand, be so good as to have them
addressed to Christopher Fisher (a most loving friend and
patron of all learned men, and you amongst the rest), in
whose family I am now a guest.’ Paris, 1504 [in error for
1505].
Thus had the poor scholar worked on, for the most part in silence,
during these years, struggling alone, yet manfully, in the midst of
the manifold hindrances cast in his way by ill-health and straitened
means, neither free-born (as his friend Colet was), and thus able to
tread unencumbered the path of duty, nor finding himself able even
‘with a great sum to obtain freedom’ for a while. Yet through all had
Erasmus kept courageously to the collar, steadily toiling on through
five years of preliminary labours, with earnest purpose to redeem his
promise to Colet—first, fully to equip himself with the proper tools
and then, but not till then, to join him in fellow work.
Why Colet
had not
written.
Colet surely had forgotten the promise of Erasmus on leaving
Oxford, or perchance the hope it held out was too slender for him to
rest on, else he would hardly have left him during these years
without letters of brotherly encouragement.
It is true that Erasmus still confessed himself to be occupied in
merely preliminary labours. His great work, no less than it had been
five years before, was still in the future. Yet the fire caught from his
contact with Colet at Oxford was at least flickering on the hearth,
and with fresh stirring and fuel might perhaps after all be kindled
into active flame.
Colet’s reply to this letter has not come down to us, but from the
result we may be sure that it contained a pressing invitation to
revisit England, and the promise of a warm reception.
VI. THE ‘ENCHIRIDION,’ ETC. OF ERASMUS (1501-5).
In the meantime, closer inspection of the literary present sent by
Erasmus, must have proved to Colet to how large an extent, after so
long a process of study and digestion, his friend had really adopted
the views which he himself had held and consistently preached for
the last ten years.
The
‘Enchiridio
n.’
The ‘Enchiridion’ was, in truth, a re-echo of the very key-note of
Colet’s faith. It openly taught, as Colet now for so many years had
been teaching, that the true Christian’s religion, instead of consisting
in the acceptance of scholastic dogmas, or the performance of
outward rites and ceremonies, really consists in a true, self-
sacrificing loyalty to Christ, his ever-living Prince; that life is a
warfare, and that the Christian must sacrifice his evil lusts and
passions, and spend his strength, not in the pursuit of his own
pleasure, but in active service of his Prince;—such was the drift and
spirit of this ‘Handybook of the Christian Soldier.’[304]
It must not be assumed, however, that Erasmus had adopted all the
views which Colet had expressed in their many conversations at
Oxford. On the contrary, I think there may be traced in the
‘Enchiridion’[305] a tendency to interpret the text of Scripture
allegorically, rather than to seek out its literal meaning—a tendency
which must have been somewhat opposed to the strong convictions
of Colet, and even to those of Erasmus, in after years. But he had
just then been studying Origen, and it is not strange that he should
for a while be fascinated, as so many others have been, by the
allegorical method of interpretation adopted by that father. He had
learned so much from his writings, that he yielded the more readily
perhaps in this particular to the force of Origen’s rich imagination.
[306]
Not a
success at
first.
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!
textbookfull.com

More Related Content

Similar to Functional Programming in C#: How to write better C# code 1st Edition Enrico Buonanno (20)

PDF
Functional Thinking Paradigm Over Syntax.pdf
Douglas Fernandes
 
PPTX
Functional Paradigm.pptx
FurretMaster
 
PDF
Beyond PITS, Functional Principles for Software Architecture
Jayaram Sankaranarayanan
 
PDF
Functional programming is the most extreme programming
samthemonad
 
PPTX
Why functional programming in C# & F#
Riccardo Terrell
 
PPTX
Столпы функционального программирования для адептов ООП, Николай Мозговой
Sigma Software
 
ODP
Functional programming
S M Asaduzzaman
 
PDF
Functional programming in C++
Alexandru Bolboaca
 
PPTX
How Functional Programming Made Me A Better Developer
Cameron Presley
 
PPTX
Functional programming
PiumiPerera7
 
PPTX
Functional programming
Prashant Kalkar
 
PDF
Introduction to functional programming
Konrad Szydlo
 
PDF
A Functional Approach to Java: Augmenting Object-Oriented Java Code with Func...
romergalbowx
 
PPTX
Functional programming for the Advanced Beginner
Luis Atencio
 
PDF
Functional programming in Python 1st Edition David Mertz
nkossivilana87
 
PPTX
When life gives you functions make functional programs!
Aaron Levin
 
PDF
Functional Programming Principles & Patterns
zupzup.org
 
PPTX
Break Free with Managed Functional Programming: An Introduction to F#
Dave Fancher
 
PPTX
Break Free with Managed Functional Programming: An Introduction to F#
IndyMobileNetDev
 
PDF
Functional programming techniques in regular JavaScript
Pavel Klimiankou
 
Functional Thinking Paradigm Over Syntax.pdf
Douglas Fernandes
 
Functional Paradigm.pptx
FurretMaster
 
Beyond PITS, Functional Principles for Software Architecture
Jayaram Sankaranarayanan
 
Functional programming is the most extreme programming
samthemonad
 
Why functional programming in C# & F#
Riccardo Terrell
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Sigma Software
 
Functional programming
S M Asaduzzaman
 
Functional programming in C++
Alexandru Bolboaca
 
How Functional Programming Made Me A Better Developer
Cameron Presley
 
Functional programming
PiumiPerera7
 
Functional programming
Prashant Kalkar
 
Introduction to functional programming
Konrad Szydlo
 
A Functional Approach to Java: Augmenting Object-Oriented Java Code with Func...
romergalbowx
 
Functional programming for the Advanced Beginner
Luis Atencio
 
Functional programming in Python 1st Edition David Mertz
nkossivilana87
 
When life gives you functions make functional programs!
Aaron Levin
 
Functional Programming Principles & Patterns
zupzup.org
 
Break Free with Managed Functional Programming: An Introduction to F#
Dave Fancher
 
Break Free with Managed Functional Programming: An Introduction to F#
IndyMobileNetDev
 
Functional programming techniques in regular JavaScript
Pavel Klimiankou
 

Recently uploaded (20)

PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Ad

Functional Programming in C#: How to write better C# code 1st Edition Enrico Buonanno

  • 1. Functional Programming in C#: How to write better C# code 1st Edition Enrico Buonanno download https://textbookfull.com/product/functional-programming-in-c-how- to-write-better-c-code-1st-edition-enrico-buonanno/ Download more ebook from https://textbookfull.com
  • 2. We believe these products will be a great fit for you. Click the link to download now, or visit textbookfull.com to discover even more! Functional Python Programming: Use a functional approach to write succinct, expressive, and efficient Python code, 3rd Edition Lott https://textbookfull.com/product/functional-python-programming- use-a-functional-approach-to-write-succinct-expressive-and- efficient-python-code-3rd-edition-lott/ Effective C An introduction to professional C programming 1st Edition Robert C. Seacord https://textbookfull.com/product/effective-c-an-introduction-to- professional-c-programming-1st-edition-robert-c-seacord/ Learn C++ by Example: Covers Versions 11 to 23 (Final Release) 1 / converted Edition Frances Buontempo https://textbookfull.com/product/learn-c-by-example-covers- versions-11-to-23-final-release-1-converted-edition-frances- buontempo/ Introduction to Programming with C 1st Edition Nhce https://textbookfull.com/product/introduction-to-programming- with-c-1st-edition-nhce/
  • 3. Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards 1st Edition Slobodan Dmitrovi■ https://textbookfull.com/product/modern-c-for-absolute-beginners- a-friendly-introduction-to-c-programming-language- and-c11-to-c20-standards-1st-edition-slobodan-dmitrovic/ C Programming Complete Guide to Learn the Basics of C Programming in 7 days 2nd Edition Xavier S Martin https://textbookfull.com/product/c-programming-complete-guide-to- learn-the-basics-of-c-programming-in-7-days-2nd-edition-xavier-s- martin/ Functional Programming in JavaScript How to improve your JavaScript programs using functional techniques First Edition Luis Atencio https://textbookfull.com/product/functional-programming-in- javascript-how-to-improve-your-javascript-programs-using- functional-techniques-first-edition-luis-atencio/ Functional Programming in JavaScript How to improve your JavaScript programs using functional techniques 1 edition Edition Luis Atencio https://textbookfull.com/product/functional-programming-in- javascript-how-to-improve-your-javascript-programs-using- functional-techniques-1-edition-edition-luis-atencio/ 101 Challenges In C Programming 1st Edition Yashavant Kanetkar https://textbookfull.com/product/101-challenges-in-c- programming-1st-edition-yashavant-kanetkar/
  • 5. Functional Programming in C#: How to write better C# code Enrico Buonanno
  • 6. Copyright For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: [email protected] ©2018 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Development editor: Marina Michaels Technical development editor: Joel Kotarski Review editor: Aleksandar Dragosavljević Project editor: Kevin Sullivan Copyeditor: Andy Carroll Proofreader: Melody Dolab Technical proofreaders: Paul Louth, Jürgen Hoetzel Typesetter: Gordan Salinovic Cover designer: Leslie Haimes Cartoons: Viseslav Radović, Richard Sheppard Graphic illustrations: Chuck Larson ISBN 9781617293955 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – EBM – 22 21 20 19 18 17
  • 8. Brief Table of Contents Copyright Brief Table of Contents Table of Contents Preface Acknowledgments About this Book 1. Core concepts Chapter 1. Introducing functional programming Chapter 2. Why function purity matters Chapter 3. Designing function signatures and types Chapter 4. Patterns in functional programming Chapter 5. Designing programs with function composition 2. Becoming functional Chapter 6. Functional error handling Chapter 7. Structuring an application with functions Chapter 8. Working effectively with multi-argument functions Chapter 9. Thinking about data functionally Chapter 10. Event sourcing: a functional approach to persistence 3. Advanced techniques Chapter 11. Lazy computations, continuations, and the beauty of monadic composition Chapter 12. Stateful programs and stateful computations Chapter 13. Working with asynchronous computations Chapter 14. Data streams and the Reactive Extensions Chapter 15. An introduction to message-passing concurrency Epilogue: what next?
  • 9. Inverted chapter dependency graph The core functions of FP Index List of Figures List of Tables List of Listings
  • 10. Table of Contents Copyright Brief Table of Contents Table of Contents Preface Acknowledgments About this Book 1. Core concepts Chapter 1. Introducing functional programming 1.1. What is this thing called functional programming? 1.1.1. Functions as first-class values 1.1.2. Avoiding state mutation 1.1.3. Writing programs with strong guarantees 1.2. How functional a language is C#? 1.2.1. The functional nature of LINQ 1.2.2. Functional features in C# 6 and C# 7 1.2.3. A more functional future for C#? 1.3. Thinking in functions 1.3.1. Functions as maps 1.3.2. Representing functions in C# 1.4. Higher-order functions 1.4.1. Functions that depend on other functions 1.4.2. Adapter functions 1.4.3. Functions that create other functions 1.5. Using HOFs to avoid duplication 1.5.1. Encapsulating setup and teardown into a HOF
  • 11. 1.5.2. Turning the using statement into a HOF 1.5.3. Tradeoffs of HOFs 1.6. Benefits of functional programming Exercises Summary Chapter 2. Why function purity matters 2.1. What is function purity? 2.1.1. Purity and side effects 2.1.2. Strategies for managing side effects 2.2. Purity and concurrency 2.2.1. Pure functions parallelize well 2.2.2. Parallelizing impure functions 2.2.3. Avoiding state mutation 2.3. Purity and testability 2.3.1. In practice: a validation scenario 2.3.2. Bringing impure functions under test 2.3.3. Why testing impure functions is hard 2.3.4. Parameterized unit tests 2.3.5. Avoiding header interfaces 2.4. Purity and the evolution of computing Exercises Summary Chapter 3. Designing function signatures and types 3.1. Function signature design 3.1.1. Arrow notation 3.1.2. How informative is a signature?3.2. Capturing data with data objects
  • 12. 3.2.1. Primitive types are often not specific enough 3.2.2. Constraining inputs with custom types 3.2.3. Writing “honest” functions 3.2.4. Composing values with tuples and objects 3.3. Modeling the absence of data with Unit 3.3.1. Why void isn’t ideal 3.3.2. Bridging the gap between Action and Func with Unit 3.4. Modeling the possible absence of data with Option 3.4.1. The bad APIs you use every day 3.4.2. An introduction to the Option type 3.4.3. Implementing Option 3.4.4. Gaining robustness by using Option instead of null 3.4.5. Option as the natural result type of partial functions Exercises Summary Chapter 4. Patterns in functional programming 4.1. Applying a function to a structure’s inner values 4.1.1. Mapping a function onto a sequence 4.1.2. Mapping a function onto an Option 4.1.3. How Option raises the level of abstraction 4.1.4. Introducing functors 4.2. Performing side effects with ForEach 4.3. Chaining functions with Bind 4.3.1. Combining Option-returning functions 4.3.2. Flattening nested lists with Bind 4.3.3. Actually, it’s called a monad 4.3.4. The Return function
  • 13. 4.3.5. Relation between functors and monads 4.4. Filtering values with Where 4.5. Combining Option and IEnumerable with Bind 4.6. Coding at different levels of abstraction 4.6.1. Regular vs. elevated values 4.6.2. Crossing levels of abstraction 4.6.3. Map vs. Bind, revisited 4.6.4. Working at the right level of abstraction Exercises Summary Chapter 5. Designing programs with function composition 5.1. Function composition 5.1.1. Brushing up on function composition 5.1.2. Method chaining 5.1.3. Composition in the elevated world 5.2. Thinking in terms of data flow 5.2.1. Using LINQ’s composable API 5.2.2. Writing functions that compose well 5.3. Programming workflows 5.3.1. A simple workflow for validation 5.3.2. Refactoring with data flow in mind 5.3.3. Composition leads to greater flexibility 5.4. An introduction to functional domain modeling 5.5. An end-to-end server-side workflow 5.5.1. Expressions vs. statements 5.5.2. Declarative vs. imperative 5.5.3. The functional take on layering
  • 14. Exercises Summary 2. Becoming functional Chapter 6. Functional error handling 6.1. A safer way to represent outcomes 6.1.1. Capturing error details with Either 6.1.2. Core functions for working with Either 6.1.3. Comparing Option and Either 6.2. Chaining operations that may fail 6.3. Validation: a perfect use case for Either 6.3.1. Choosing a suitable representation for errors 6.3.2. Defining an Either-based API 6.3.3. Adding validation logic 6.4. Representing outcomes to client applications 6.4.1. Exposing an Option-like interface 6.4.2. Exposing an Either-like interface 6.4.3. Returning a result DTO 6.5. Variations on the Either theme 6.5.1. Changing between different error representations 6.5.2. Specialized versions of Either 6.5.3. Refactoring to Validation and Exceptional 6.5.4. Leaving exceptions behind? Exercises Summary Chapter 7. Structuring an application with functions 7.1. Partial application: supplying arguments piecemeal 7.1.1. Manually enabling partial application
  • 15. 7.1.2. Generalizing partial application 7.1.3. Order of arguments matters 7.2. Overcoming the quirks of method resolution 7.3. Curried functions: optimized for partial application 7.4. Creating a partial-application-friendly API 7.4.1. Types as documentation 7.4.2. Particularizing the data access function 7.5. Modularizing and composing an application 7.5.1. Modularity in OOP 7.5.2. Modularity in FP 7.5.3. Comparing the two approaches 7.5.4. Composing the application 7.6. Reducing a list to a single value 7.6.1. LINQ’s Aggregate method 7.6.2. Aggregating validation results 7.6.3. Harvesting validation errors Exercises Summary Chapter 8. Working effectively with multi-argument functions 8.1. Function application in the elevated world 8.1.1. Understanding applicatives 8.1.2. Lifting functions 8.1.3. An introduction to property-based testing 8.2. Functors, applicatives, monads 8.3. The monad laws 8.3.1. Right identity 8.3.2. Left identity
  • 16. 8.3.3. Associativity 8.3.4. Using Bind with multi-argument functions 8.4. Improving readability by using LINQ with any monad 8.4.1. Using LINQ with arbitrary functors 8.4.2. Using LINQ with arbitrary monads 8.4.3. let, where, and other LINQ clauses 8.5. When to use Bind vs. Apply 8.5.1. Validation with smart constructors 8.5.2. Harvesting errors with the applicative flow 8.5.3. Failing fast with the monadic flow Exercises Summary Chapter 9. Thinking about data functionally 9.1. The pitfalls of state mutation 9.2. Understanding state, identity, and change 9.2.1. Some things never change 9.2.2. Representing change without mutation 9.3. Enforcing immutability 9.3.1. Immutable all the way down 9.3.2. Copy methods without boilerplate? 9.3.3. Leveraging F# for data types 9.3.4. Comparing strategies for immutability: an ugly contest 9.4. A short introduction to functional data structures 9.4.1. The classic functional linked list 9.4.2. Binary trees Exercises Summary
  • 17. Chapter 10. Event sourcing: a functional approach to persistence 10.1. Thinking functionally about data storage 10.1.1. Why data storage should be append-only 10.1.2. Relax, and forget about storing state 10.2. Event sourcing basics 10.2.1. Representing events 10.2.2. Persisting events 10.2.3. Representing state 10.2.4. An interlude on pattern matching 10.2.5. Representing state transitions 10.2.6. Reconstructing the current state from past events 10.3. Architecture of an event-sourced system 10.3.1. Handling commands 10.3.2. Handling events 10.3.3. Adding validation 10.3.4. Creating views of the data from events 10.4. Comparing different approaches to immutable storage 10.4.1. Datomic vs. Event Store 10.4.2. How event-driven is your domain?Summary 3. Advanced techniques Chapter 11. Lazy computations, continuations, and the beauty of monadic composition 11.1. The virtue of laziness 11.1.1. Lazy APIs for working with Option 11.1.2. Composing lazy computations 11.2. Exception handling with Try 11.2.1. Representing computations that may fail
  • 18. 11.2.2. Safely extracting information from a JSON object 11.2.3. Composing computations that may fail 11.2.4. Monadic composition: what does it mean? 11.3. Creating a middleware pipeline for DB access 11.3.1. Composing functions that perform setup/teardown 11.3.2. A recipe against the pyramid of doom 11.3.3. Capturing the essence of a middleware function 11.3.4. Implementing the query pattern for middleware 11.3.5. Adding middleware that times the operation 11.3.6. Adding middleware that manages a DB transaction Summary Chapter 12. Stateful programs and stateful computations 12.1. Programs that manage state 12.1.1. Maintaining a cache of retrieved resources 12.1.2. Refactoring for testability and error handling 12.1.3. Stateful computations 12.2. A language for generating random data 12.2.1. Generating random integers 12.2.2. Generating other primitives 12.2.3. Generating complex structures 12.3. A general pattern for stateful computations Summary Chapter 13. Working with asynchronous computations 13.1. Asynchronous computations 13.1.1. The need for asynchrony 13.1.2. Representing asynchronous operations with Task 13.1.3. Task as a container for a future value
  • 19. 13.1.4. Handling failure 13.1.5. An HTTP API for currency conversion 13.1.6. If it fails, try a few more times 13.1.7. Running asynchronous operations in parallel 13.2. Traversables: working with lists of elevated values 13.2.1. Validating a list of values with monadic Traverse 13.2.2. Harvesting validation errors with applicative Traverse 13.2.3. Applying multiple validators to a single value 13.2.4. Using Traverse with Task to await multiple results 13.2.5. Defining Traverse for single-value structures 13.3. Combining asynchrony and validation (or any other two monadic effects) 13.3.1. The problem of stacked monads 13.3.2. Reducing the number of effects 13.3.3. LINQ expressions with a monad stack Summary Chapter 14. Data streams and the Reactive Extensions 14.1. Representing data streams with IObservable 14.1.1. A sequence of values in time 14.1.2. Subscribing to an IObservable 14.2. Creating IObservables 14.2.1. Creating a timer 14.2.2. Using Subject to tell an IObservable when it should signal 14.2.3. Creating IObservables from callback-based subscriptions 14.2.4. Creating IObservables from simpler structures 14.3. Transforming and combining data streams 14.3.1. Stream transformations 14.3.2. Combining and partitioning streams
  • 20. 14.3.3. Error handling with IObservable 14.3.4. Putting it all together 14.4. Implementing logic that spans multiple events 14.4.1. Detecting sequences of pressed keys 14.4.2. Reacting to multiple event sources 14.4.3. Notifying when an account becomes overdrawn 14.5. When should you use IObservable? Summary Chapter 15. An introduction to message-passing concurrency 15.1. The need for shared mutable state 15.2. Understanding message-passing concurrency 15.2.1. Implementing agents in C# 15.2.2. Getting started with agents 15.2.3. Using agents to handle concurrent requests 15.2.4. Agents vs. actors 15.3. Functional APIs, agent-based implementations 15.3.1. Agents as implementation details 15.3.2. Hiding agents behind a conventional API 15.4. Message-passing concurrency in LOB applications 15.4.1. Using an agent to synchronize access to account data 15.4.2. Keeping a registry of accounts 15.4.3. An agent is not an object 15.4.4. Putting it all together Summary Epilogue: what next? Inverted chapter dependency graph The core functions of FP
  • 21. Index List of Figures List of Tables List of Listings
  • 22. Preface Today, functional programming (FP) is no longer brooding in the research departments of universities; it has become an important and exciting part of mainstream programming. The majority of the languages and frameworks created in the last decade are functional, leading some to predict that the future of programming is functional. Meanwhile, popular object-oriented languages like C# and Java see the introduction of more functional features with every new release, enabling a multiparadigm programming style. And yet, adoption in the C# community has been slow. Why is this so? One reason, I believe, is the lack of good literature: Most FP literature is written in and for functional languages, especially Haskell. For developers with a background in OOP, this poses a programming-language barrier to learning the concepts. Even though many of the concepts apply to a multiparadigm language like C#, learning a new paradigm and a new language at once is a tall order. Even more importantly, most of the books in the literature tend to illustrate functional techniques and concepts with examples from the domains of mathematics or computer science. For the majority of programmers who work on line-of-business (LOB) applications day in and day out, this creates a domain gap and leaves them wondering how relevant these techniques may be for real-world applications. These shortcomings posed major stumbling blocks in my own path to learning FP. After tossing aside the n-th book that explained something known as currying by showing how the add function can be curried with the number 3, creating a function that can add 3 to any number (can you think of any application where this would be even remotely useful?), I decided to pursue my own research path. This involved learning half a dozen functional languages (some better than others), and seeing which concepts from FP could be effectively applied in C# and in the kind of applications most developers are paid to write, and it culminated in the writing of this book. This book bridges the language gap for C# developers by showing how you can leverage functional techniques in this language. It also bridges the domain gap by showing how these techniques can be applied to typical business scenarios. I take a pragmatic approach and cover functional techniques to the extent that they’re useful in a typical LOB application scenario, and dispense with most of the theory behind FP. Ultimately, you should care about FP because it gives you the following: Power— This simply means that you can get more done with less code. FP raises the level of abstraction, allowing you to write high-level code while freeing you from low-level technicalities that add complexity but no value. Safety— This is especially true when dealing with concurrency. A program written in the imperative style may work well in a single-threaded implementation but cause all sorts of bugs when concurrency comes in. Functional code offers much better guarantees in concurrent scenarios, so it’s only natural that we’re seeing a surge of interest in FP in the era of multicore processors. Clarity— We spend more time maintaining and consuming existing code than writing new code, so it’s important that our code be clear and intention-revealing. As you learn to think functionally, achieving this clarity will become more natural.
  • 23. If you’ve been programming in an object-oriented style for some time, it may take a bit of effort and willingness to experiment before the concepts in this book come to fruition. To make sure learning FP is an enjoyable and rewarding process, I have two recommendations: Be patient— You may have to read some sections more than once. You may put the book down for a few weeks and find that when you pick it up again, something that seemed obscure suddenly starts to make sense. Experiment in code— You won’t learn unless you get your hands dirty. The book provides many examples and exercises, and many of the code snippets can be tested in the REPL. Your colleagues may be less eager to explore than you. Expect them to protest your adoption of this new style and to look perplexed at your code and say things like, “why not just do x?” (where x is boring, obsolete, and usually harmful). Don’t discuss. Just sit back and watch them eventually turn around and use your techniques to solve issues they run into again and again.
  • 24. Acknowledgments I’d like to thank Paul Louth, who not only provided inspiration through his LanguageExt library— from which I borrowed many good ideas—but who also graciously reviewed the book at various stages. Manning’s thorough editorial process ensured that the quality of this book is infinitely better than if I had been left to my own means. For this, I’d like to thank the team that collaborated on the book, including Mike Stephens, development editor Marina Michaels, technical editor Joel Kotarski, technical proofreader Jürgen Hoetzel, and copyeditor Andy Carroll. Special thanks to Daniel Marbach and Tamir Dresher for their technical insights, as well as to all those who took part in the peer reviews, including Alex Basile, Aurélien Gounot, Blair Leduc, Chris Frank, Daniel Marbach, Devon Burriss, Gonzalo Barba López, Guy Smith, Kofi Sarfo, Pauli Sutelainen, Russell Day, Tate Antrim, and Wayne Mather. Thanks to Scott Wlaschin for sharing his articles at http://fsharpforfunandprofit.com, and to the many other members of the FP community who share their knowledge and enthusiasm through articles, blogs, and open source.
  • 25. About this Book This book aims to show how you can leverage functional techniques in C# to write code that is concise, elegant, robust, and maintainable.
  • 26. Who should read this book This book is for an ambitious breed of developer. You know the C# language and the .NET framework. You have experience developing real-world applications and are familiar with OOP concepts, patterns, and best practices. Yet, you’re looking to expand your arsenal by learning functional techniques so that you can make the most out of C# as a multiparadigm language. If you’re trying or planning to learn a functional language, this book will also be hugely valuable, because you’ll learn how to think functionally in a language you’re familiar with. Changing the way you think is the hard part; once that’s achieved, learning the syntax of any particular language will be relatively easy.
  • 27. How this book is organized The book consists of 15 chapters, divided into 3 parts: Part 1 covers the basic techniques and principles of functional programming. We’ll start by looking at what functional programming is and how C# supports programming in a functional style. We’ll then look at the power of higher-order functions, function purity and its relation to testability, the design of types and function signatures, and how simple functions can be composed into complex programs. By the end of part 1, you’ll have a good feel for what a program written in a functional style looks like and for the benefits that this style has to offer. With these basic concepts covered, we’ll pick up some speed in part 2 and move on to wider-reaching concerns, such as functional error handling, modularizing and composing an application, and the functional approach to understanding state and representing change. By the end of part 2, you’ll have acquired a set of tools enabling you to effectively tackle many programming tasks using a functional approach. Part 3 will tackle more advanced topics, including lazy evaluation, stateful computations, asynchrony, data streams, and concurrency. Each chapter in part 3 introduces important techniques that have the potential to completely change the way you write and think about software. You’ll find a more detailed breakdown of the topics in each chapter, and a representation of what chapters are required before reading any particular chapter, on the inside front cover page. Coding for real-world applications The book aims to stay true to real-world scenarios. To do this, many examples deal with practical tasks such as reading configuration, connecting to a database, validating HTTP requests, and so on—things you may already know how to do, but you’ll see them with the fresh perspective of functional thinking. Throughout the book, I use a long-running example to illustrate how FP can help when writing LOB applications. For this, I’ve chosen an online banking application for the fictitious Bank of Codeland (BOC)—naff, I know, but at least it has the obligatory three-letter acronym. Because most people have access to an online banking facility, it should be easy to imagine the required functionality and plain to see how the problems discussed are relevant to real-world applications. I also use scenarios to illustrate how to solve typical programming problems in a functional style. The constant back and forth between practical examples and FP concepts will hopefully help bridge the gap between theory and practice—something I found wanting in the existing literature, as I mentioned. Leveraging functional libraries A language like C# may have functional features, but to fully leverage these you’ll often use libraries that facilitate common tasks. Microsoft has provided several libraries that facilitate programming in a functional style, including these: System.Linq—Yes, in case you didn’t know, it’s a functional library! I assume you’re
  • 28. familiar with it, given that it’s such an important part of .NET. System.Collections.Immutable—This is a library of immutable collections, which we’ll start using in chapter 9. System.Reactive—This is an implementation of the Reactive Extensions for .NET, allowing you to work with data streams, which we’ll discuss in chapter 14. This still leaves out plenty of other important types and functions that are staples of FP. As a result, several independent developers have written libraries to fill those gaps. To date, the most complete of these is LanguageExt, a library written by Paul Louth to improve the C# developer’s experience when coding functionally.[1] 1 LanguageExt is open source and available on GitHub and NuGet: https://github.com/louthy/language-ext. In the book, I don’t use LanguageExt directly; instead, I’ll show you how I developed my own library of functional utilities, called LaYumba.Functional, even though it largely overlaps with LanguageExt. This is pedagogically more useful, for several reasons: The code will remain stable after the book is published. You get to look under the hood and see that powerful functional constructs are deceptively simple to define. You can concentrate on the essentials: I’ll show you the constructs in their purest form, so that you won’t be distracted by the details and edge cases that a full-fledged library addresses.
  • 29. Code conventions and downloads The code samples are in C# 7, and for the most part are compatible with C# 6. Language features specifically introduced in C# 7 are only used in chapter 10 and beyond (and in a couple of samples in section 1.2 that explicitly showcase C# 7). You can execute many of the shorter snippets of code in a REPL, thereby gaining hands-on practice with immediate feedback. The more extended examples are available for download at https://github.com/la-yumba/functional-csharp-code, along with the exercises’ setup and solutions. Code listings in the book focus on the topic being discussed, and therefore may omit namespaces, using statements, trivial constructors, or sections of code that appeared in a previous listing and remain unchanged. If you’d like to see the full, compiling version of a listing, you’ll find it in the code repository: https://github.com/la-yumba/functional-csharp-code.
  • 30. Book forum Purchase of Functional Programming in C# includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the author and from other users. To access the forum, go to https://forums.manning.com/forums/functional-programming-in-c-sharp. You can also learn more about Manning’s forums and the rules of conduct at https://forums.manning.com/forums/about. Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions lest his interest stray! The forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.
  • 31. About the author Enrico Buonanno obtained an MS in Computer Science at Columbia University in 2001 and has been working as a software developer and architect since. He’s worked on mission-critical projects for prestigious companies in FinTech (including the Bank for International Settlements, Barclays, and UBS) and other technology-driven businesses.
  • 32. Part 1. Core concepts In this part we’ll cover the basic techniques and principles of functional programming. Chapter 1 starts by looking at what functional programming is, and how C# supports programming in a functional style. It then delves deeper into higher-order functions, a fundamental technique of FP. Chapter 2 explains what pure functions are, why purity has important implications for a function’s testability, and why pure functions lend themselves well to parallelization and other optimizations. Chapter 3 deals with principles for designing types and function signatures—things you thought you knew but that receive a breath of fresh air when looked at from a functional perspective. Chapter 4 introduces some of the core functions of FP: Map, Bind, ForEach, and Where (filter). These functions provide the basic tools for interacting with the most common data structures in FP. Chapter 5 shows how functions can be chained into pipelines that capture the workflows of your program. It then widens the scope to developing a whole use case in a functional style. By the end of part 1, you’ll have a good feel for what a program written in a functional style looks like, and you’ll understand the benefits that this style has to offer.
  • 33. Exploring the Variety of Random Documents with Different Content
  • 34. He had now taken to wearing an ‘inner sharp shirt of hair,’ and to sleeping on the bare boards of his chamber, with a log under his head for a pillow, and was otherwise schooling, by his powerful will, his quick and buoyant nature into accordance with the strict rules of the Carthusian brotherhood.[259] It was a critical moment in his life. Soon after his father had been imprisoned and fined, having some business with Fox, Bishop of Winchester, that great courtier called him aside, pretending to be his friend, and promised that if he would be ruled by him, he would not fail to restore him into the King’s favour. But Fox was only setting a trap for him, from which he was saved by a friendly hint from Whitford,[260] the bishop’s chaplain. This man told More that his master would not stick to agree to his own father’s death to serve the King’s turn, and advised him to keep quite aloof from the King. This hint was not reassuring, but it may have saved More’s life. What would have happened to him had he been left alone with misadvising friends to give hasty vent to the disappointment which thus had crushed his hopes at the very outset of his career—whether the cloister would have received him as it did his friend Whitford afterwards, to be another ‘wretch of Sion,’ none can tell. When Colet comes to London, More chooses him as his spiritual guide. More’s letter to Colet. More alludes to Colet’s preaching
  • 35. at St. Paul’s. Happily for him it was at this critical moment that Colet came up to London to assume his new duties at St. Paul’s. More was a diligent listener to his sermons, and chose him as his father confessor. Stapleton has preserved a letter from More to Colet,[261] which throws much light upon the relation between them. It was written in October, 1504, whilst Colet, after preaching during the summer, was apparently spending his long vacation in the country. It shows that, under Colet’s advice, More was not altogether living the life of a recluse. Colet had for some time been absent from his pulpit at St. Paul’s. As More was one day walking up and down Westminster Hall, waiting while other people’s suits were being tried, he chanced to meet Colet’s servant. Learning from him that his master had not yet returned to town, More wrote to Colet this letter, to tell him how much he missed his wonted delightful intercourse with him. He told him how he had ever prized his most wise counsel; how by his most delightful fellowship he had been refreshed; how by his weighty sermons he had been roused, and by his example helped on his way. He reminded him how fully he relied upon his guidance—how he had been wont to hang upon his very beck and nod. Under his protection he had felt himself gaining strength, now without it he was flagging and undone. He acknowledged that, by following Colet’s leading, he had escaped almost from the very jaws of hell; but now, amid all the temptations of city life and the noisy wrangling of the law courts, he felt himself losing ground without his help. No doubt the country might be much more pleasant to Colet than the city, but the city, with all its vice, and follies, and temptations, had far more need of his skill than simple country folk! ‘There sometimes come, indeed,’ he added, ‘into the pulpit at St. Paul’s, men who promise to heal the diseases of the people. But, though they seem to have preached plausibly enough, their lives so jar with their words that they stir up men’s wounds, rather than heal them.’ But, he said, his fellow- citizens had confidence in Colet, and all longed for his return. He
  • 36. urged him, therefore, to return speedily, for their sake and for his, reminding Colet again that he had submitted himself in all things to his guidance. ‘Meanwhile,’ he concluded, ‘I shall spend my time with Grocyn, Linacre, and Lilly; the first, as you know, is the director of my life in your absence; the second, the master of my studies; the third, my most dear companion. Farewell, and, as you do, ever love me.’ ‘London: 10 Calend. Novembris’[1504].[262] More buries himself in his studies with Lilly. Surrounded as he was by Colet, Grocyn, and Linacre, More soon began to devote his leisure to his old studies. Lilly, too, had returned home well versed in Greek. He had spent some years in the island of Rhodes, to perfect his knowledge of it.[263] Naturally enough, therefore, the two friends busied themselves in jointly translating Greek epigrams;[264] and as, with increasing zeal, they yielded to the charms of the new learning, it is not surprising if the fascinations of monastic life began to lose their hold upon their minds. The result was that More was saved from the false step he once had contemplated. He had, it would seem, seen enough of the evil side of the ‘religious life’ to know that in reality it did not offer that calm retreat from the world which in theory it ought to have done. He had cautiously abstained from rushing into vows before he had learned well what they meant; and his experience of ascetic practices had far too ruthlessly destroyed any pleasant pictures of monastic life in which he may have indulged at first, to admit of his ever becoming a Carthusian monk. Still we may not doubt that, in truth, he had a real and natural yearning for the pure ideal of cloister holiness. Early disappointed love possibly,[265] added to the rude shipwreck made of his worldly
  • 37. fortunes on the rock of royal displeasure, had, we may well believe, effectually taught him the lesson not to trust in those ‘gay golden dreams’ of worldly greatness, from which, he was often wont to say, ‘we cannot help awaking when we die;’ and even the penances and scourgings inflicted by way of preparatory discipline upon his ‘wanton flesh,’ though soon proved to be of no great efficacy, were not the less without some deep root in his nature; else why should he wear secretly his whole life long the ‘sharp shirt of hair’ which we hear about at last?[266] So much as this must be conceded to More’s Catholic biographers, who naturally incline to make the most of this ascetic phase of his life.[267] More disgusted with the cloister. But that, on the other hand, he did turn in disgust from the impurity of the cloister to the better chances which, he thought, the world offered of living a chaste and useful life, we know from Erasmus; and this his Catholic biographers have, in their turn, acknowledged. [268] IV. MORE STUDIES PICO’S LIFE AND WORKS. HIS MARRIAGE (1505). More appears to have been influenced in the course he had taken, mainly by two things:—first, a sort of hero-worship for the great Italian, Pico della Mirandola; and, secondly, his continued reverence for Colet. More translates the life and works of Pico.
  • 38. Pico’s warm piety and zeal. A layman to the end. The ‘Life of Pico,’ with divers Epistles and other ‘Works’ of his, had come into More’s hands. Very probably Lilly may have brought them home with him amongst his Italian spoils. More had taken the pains to translate them into English. He had doubtless heard all about Pico’s outward life from those of his friends who had known him personally when in Italy. But here was the record of Pico’s inner history, for the most part in his own words; and reading this in More’s translation, it is not hard to see how strong an influence it may have exercised upon him. It told how, suddenly checked, as More himself had been, in a career of worldly honour and ambition, the proud vaunter of universal knowledge had been transformed into the humble student of the Bible; how he had learned to abhor scholastic disputations, of which he had been so great a master, and to search for truth instead of fame. It told how, ‘giving no great force to outward observances,’ ‘he cleaved to God in very fervent love,’ so that, ‘on a time as he walked with his nephew in an orchard at Ferrara, in talking of the love of Christ, he told him of his secret purpose to give away his goods to the poor, and fencing himself with the crucifix, barefoot, walking about the world, in every town and castle to preach of Christ.’ It told how he, too, ‘scourged his own flesh in remembrance of the passion and death that Christ suffered for our sake;’ and urged others also ever to bear in mind two things, ‘that the Son of God died for thee, and that thou thyself shall die shortly;’ and how, finally, in spite of the urgent warnings of the great Savonarola, he remained a layman to the end, and in the midst of indefatigable study of the Oriental languages, and, above all, the Scriptures, through their means, died at the early age of thirty-five, leaving the world to wonder at his genius, and Savonarola to preach a sermon on his death.[269]
  • 39. The Works of Pico. And turning from the ‘Life of Pico’ to his ‘Works,’ and reading these in More’s translation, they present to the mind a type of Christianity, so opposite to the ceremonial and external religion of the monks, that one may well cease to wonder that More, having caught the spirit of Pico’s religion, could no longer entertain any notion of becoming a Carthusian brother. It will be worth while to examine carefully what these works of Pico’s were. Pico’s letter to his nephew. The first is a letter from Pico to his nephew—a letter of advice to a young man somewhat in More’s position, longing to live to some ‘virtuous purpose,’ but finding it hard to stem the tide of evil around him. To encourage his nephew, he speaks of the ‘great peace and felicity it is to the mind when a man hath nothing that grudgeth his conscience, nor is appalled with the secret touch of any privy crime.’... ‘Doubtest thou, my son, whether the minds of wicked men be vexed or not with continual thought and torment?... The wicked man’s heart is like the stormy sea, that may not rest. There is to him nothing sure, nothing peaceable, but all things fearful, all things sorrowful, all things deadly. Shall we, then, envy these men? Shall we follow them, forgetting our own country—heaven, and our own heavenly Father—where we were free-born? Shall we wilfully make ourselves bondmen, and with them, wretched living, more wretchedly die, and at the last most wretchedly in everlasting fire be punished?’ Pico’s faith in Christianity .
  • 40. Having warned his nephew against wicked companions, Pico proceeds to make evident allusion to the sceptical tendencies of Italian society. ‘It is verily a great madness’ (he says) ‘not to believe the Gospel, whose truth the blood of martyrs crieth, the voice of Apostles soundeth, miracles prove, reason confirmeth, the world testifieth, the elements speak, devils confess!’[270] ‘But,’ he continues, ‘a far greater madness is it, if thou doubt not but that the Gospel is true, to live then as though thou doubtest not but that it were false.’ Its reasonable ness and harmony with the laws of nature. Pico on prayer. Pico on the Scriptures. And it is worth notice, that the perception of the reasonableness of Christianity, and its harmony with the laws of nature, breaks out again a little further on. Pico writes to his nephew: ‘Take no heed what thing many men do, but [take heed] what thing the very law of nature, what thing very reason, what thing our Lord himself showeth thee to be done.’ A little further on Pico points out two remedies, or aids, whereby his nephew may be strengthened in his course. First, charity; and secondly, prayer. With regard to the first he wrote:—‘Certainly He shall not hear thee when thou callest on Him, if thou hear not first the poor man when he calleth upon thee.’ With regard to prayer, he wrote thus:—‘When I stir thee to prayer, I stir thee not to the prayer that standeth in many words, but to that prayer which, in the secret chamber of the mind, in the privy-closet of the soul, with very affect speaketh unto God, and in the most lightsome darkness of
  • 41. contemplation, not only presenteth the mind to the Father, but also uniteth it with Him by unspeakable ways, which only they know that have assayed. Nor I care not how long or how short thy prayer be, but how effectual, how ardent.... Let no day pass, then, but thou once at the leastwise present thyself to God by prayer, and falling down before Him flat to the ground, with an humble affect of devout mind, not from the extremity of thy lips, but out of the inwardness of thine heart, cry these words of the prophet: “The offences of my youth, and mine ignorances, remember not, good Lord, but after thy goodness remember me.” What thou shalt in thy prayer ask of God, both the Holy Spirit, which prayeth for us and eke thine own necessity, shall every hour put into thy mind, and also what thou shalt pray for thou shalt find matter enough in the reading of Holy Scripture, which that thou wouldst now (setting poets, fables, and trifles aside) take ever in thine hand I heartily pray thee; ... there lieth in them a certain heavenly strength quick and effectual, which with marvellous power transformeth and changeth the readers’ mind into the love of God, if they be clean and lowly entreated.’ Lastly, he said he would ‘make an end with this one thing. I warn thee (of which when we were last together I often talked with thee) that thou never forget these two things; that both the Son of God died for thee, and that thou thyself shalt die shortly!’[271] This, then, was the doctrine which Pico, ‘fencing himself with a crucifix, barefoot, walking about the world, in every town and castle,’ purposed to preach! The next letter is a reply to a friend of his who had urged him to leave his contemplative and studious life, and to mix in political affairs, in which, as an Italian prince, lay his natural sphere. He replied, that his desire was ‘not so to embrace Martha as utterly to forsake Mary’—to ‘love them and use them both, as well study as worldly occupation.’ ‘I set more’ (he continued) ‘by my little house,
  • 42. my study, the pleasure of my books, the rest and peace of my mind, than by all your king’s palaces, all your business, all your glory, all the advantage that ye hawke after, and all the favour of the court!’ Pico’s study of Eastern languages. Then he tells his friend that what he looks to do is, ‘to give out some books of mine to the common profit,’ and that he is mastering the Hebrew, Chaldee, and Arabic languages.[272] Another letter to his nephew. Then follows another letter to his nephew, who, in trying to follow the advice given in his first letter, finds himself slandered and called a hypocrite by his companions at court. It is a letter of noble encouragement to stand his ground, and to heed not the scoffs and sneers of his fellows. These letters are followed by an exposition of Psalm xvi., in which Pico incidentally uses his knowledge of the Hebrew text and of Eastern customs.[273] Pico’s verses. All the foregoing are in prose; after them come More’s translations of some of Pico’s verses.
  • 43. The first is entitled, ‘Twelve rules, partly exciting and partly directing a man in spiritual battle,’ and reminds one of the ‘Enchiridion’ of Erasmus. The second is named, ‘The twelve weapons of spiritual battle.’ The striking feature in both these metrical works is the holding up of Christ’s example as an incentive to duty and to love. Thus:— ‘Consider, when thou art movèd to be wroth, He who that was God and of all men the best, Seeing himself scorned and scourgèd both, And as a thief between two thievès threst, With all rebuke and shame; yet from his breast Came never sign of wrath or of disdain, But patiently endurèd all the pain!’ And again, after speaking of the shortness of life— ‘How fast it runneth on, and passen shall As doth a dream or shadow on a wall.’ he continues:— ‘Think on the very lamentable pain, Think on the piteous cross of woeful Christ, Think on his blood, beat out at every vein, Think on his precious heart carvèd in twain: Think how for thy redemption all was wrought. Let him not lose, what he so dear hath bought.’ There is another poem in which the feelings of a lover towards his love are made to show what the Christian’s feelings ought to be to Christ; and lastly, there is a solemn and beautiful ‘Prayer of Picus Mirandola to God,’ glowing with the same adoration of ... ‘that mighty love Which able was thy dreadful majesty To draw down into earth from heaven above
  • 44. And crucify God, that we poor wretches, we Should from our filthy sin yclensèd be!’ and the same earnest longing ‘That when the journey of this deadly life My silly ghost hath finished, and thence Departen must,’ ... ‘He may Thee find ... In thy lordship, not as a lord, but rather As a very tender, loving father!’ Pico’s enlightene d piety. I have made these quotations, and thus endeavoured to put the reader in possession of the contents of this little volume, which More in his seclusion was translating, because I think they throw some light upon the current in which his thoughts were moving, and because, whilst the name of Pico is known to fame as that of a great linguist and most precocious genius, his enlightened piety and the extent of the influence of his heroic example have scarcely been appreciated. This little book, indeed, has a special significance in relation to the history of the Oxford Reformers. Whatever doubt may rest upon the direct connection between their views and those of Savonarola, there is here in More’s translation of these writings of a disciple of Savonarola, another indirect connection between them and that little knot of earnest Christian men in Italy of which Savonarola was the most conspicuous. Position of the Neo- Platonic philosophe rs of Florence.
  • 45. The extracts made and translated by More from Pico’s writings may also help us to recognise in the Neo-Platonic philosophers of Florence, by whose writings Colet had been so profoundly influenced, a vein of earnest Christian feeling of which it may be that we know too little. Like their predecessors of a thousand years before, they stood between the old world and the new. They were the men who, when the learning of the old Pagan world was restored to light, and backed against the dogmatic creed of priest- ridden degraded Christendom, built a bridge, as it were, between Christian and Pagan thought. That their bridge was frail and insecure it may be, but, to a great extent, it served its end. A passage was effected by it from the Pagan to the Christian shore. Ficino, the representative Neo-Platonist, who, as has been seen, had aided in its building, had himself passed over it. Savonarola too had crossed it. Pico had crossed it. It is true that these men may, to some extent, have Platonised Christianity in becoming Christian; but it will be recognised at once that the earnest Christian feeling found by More in Pico, so to speak, rose far above his Platonism. More calls Savonarola a ‘man of God.’ That the life and writings of such a man should have awakened in his breast something of hero-worship[274] is, therefore, not surprising. That he should have singled out these passages, and taken the trouble to translate them, is some proof that he admired Pico’s practical piety more than his Neo-Platonic speculations; that he shared with Colet those yearnings for practical Christian reform with which Colet had returned from Italy ten years before. That a few years after this translation should be published and issued in English in More’s name was further proof of it. For here was a book not only in its drift and spirit boldly taking Cole’s side against the Schoolmen, and in favour of the study of Scripture and the Oriental languages, but as boldly holding up Savonarola as ‘a preacher, as well in cunning as in holiness of living, most famous,’—‘a holy
  • 46. man’—‘a man of God’[275]—in the teeth of the fact that he had been denounced by the Pope as a ‘son of blasphemy and perdition,’ excommunicated, tortured, and, refusing to abjure, hung and burned as a heretic![276] Colet’s influence on More. And if the fire of hero-worship for Pico had lit up something of heroism in More’s heart—something which yearned for the battle of life, and not for the rest of the cloister—so the living example of Colet was ready to feed the flame into strength and steadiness. More marries under Colet’s advice. The result was that, in 1505,[277] in spite of early disappointments, and, it is said, under Colet’s ‘advice and direction,’[278] More married Jane Colt, of New Hall in Essex, took a house in Bucklersbury, and gave up for ever all longings for monastic life. V. HOW IT HAD FARED WITH ERASMUS (1500-5). Soon after Colet’s elevation to the dignities of Doctor and Dean, a letter of congratulation arrived from Erasmus. Colet had written no letter to him, and had almost lost sight of him during these years. It would seem that, after his departure from Oxford, Colet had given up all hopes of his aid. Nor had any other kindred soul risen up to take that place in fellow-work beside him, which at one time he had hoped the great scholar might have filled. Erasmus had not forgotten Colet.
  • 47. The legal robbery of Erasmus at Dover. But Erasmus on his side had not forgotten Colet. His intercourse with Colet at Oxford had changed the current of his thoughts, and the course of his life. Colet little knew by what slow and painful steps he had been preparing to redeem the promise he had made on leaving Oxford. We left him making the best of his way to Dover, with his purse full of golden crowns, kindly bestowed by his English friends in order that he might now carry out his long-cherished intention of going to Italy. But the Fates had decreed against him. King Henry VII. had already reached the avaricious period of his life and reign. Under cover of an old obsolete statute, he had given orders to the Custom House officers to stop the exportation of all precious metals, and the Custom House officers in their turn, construing their instructions strictly to the letter, had seized upon Erasmus’s purseful of golden crowns, and relieved him of the burden, for the benefit of the King’s exchequer.[279] The poor scholar proceeded without them to cross to Boulogne. He was a bad sailor, and the hardships of travel soon told upon his health. He was heart-sick also; as well he might be, for this unlucky loss of his purse had utterly disconcerted once more his long- cherished plans. On his arrival at Paris, after a wretched and dangerous journey,[280] he was taken ill, and recovered only to bear his bitter disappointment as best he could. Before he had yet recovered from his illness he wrote this touching letter to Arnold, the young legal friend of More, with whom a few weeks before he and More had visited the Royal nursery. Erasmus to Arnold.[281] Erasmus gives up all
  • 48. hope of going to Italy. ‘Salve, mi Arnolde. Now for six weeks I having been suffering much from a nocturnal ague, of a lingering kind but of daily recurrence, and it has nearly killed me. I am not yet free from the disease, but still somewhat better. I don’t yet live again, but some hope of life dawns upon me. You ask me to tell you my plans. Take this only, to begin with: To mortify myself to the world, I dash my hopes. I long for nothing more than to give myself rest, in which I might live wholly to God alone, weep away the sins of a careless life, devote myself to the study of the Holy Scriptures, either read somewhat or write. This I cannot do in a monastery or college. One could not be more delicate than I am; my health will bear neither vigils, nor fasts, nor any disturbance, even when at its best. Here, where I live in such luxury, I often fall ill; what should I do amid the labours of college life? Cost of going to Italy. ‘I had determined to go to Italy this year, and to work at theology some months at Bologna; also there to take the degree of Doctor; then in the year of Jubilee to visit Rome; which done, to return to my friends and then to settle down. But I am afraid that these things that I would, I shall not be able to accomplish. I fear, in the first place, that my health would not stand such a journey and the heat of the climate. Lastly, I reckon that I could not go to Italy, nor live there without great expense. It costs a great deal also to prepare for a degree. And the Bishop of Cambray gives very sparingly. He altogether loves more liberally than he gives, and promises everything much more largely than he performs. It is partly my own fault
  • 49. for not pressing him. There are so many who are even extorting. In the meantime I shall do what seems for the best. Farewell.’ What was he to do? It was clear that he did not know what to do. The worst of it was that the unfortunate loss of the price of many months’ leisure,[282] not only obliged him to postpone sine die his project of visiting Italy, but also to spend a large portion of his time and strength for the next few years in a struggle almost for subsistence. For the wolf must in some way or other be kept from the door; and Erasmus was poor! Poverty of Erasmus. His Greek studies. Erasmus visits Holland. For a few months he struggled on at Paris, living in lodgings with an old fellow student ‘sparingly,’[283] hard at work at a collection of Greek and Latin proverbs—his Adagia—partly in order to raise the wind, partly to improve himself in Greek. Sometimes borrowing and sometimes begging, whatever money came to his hands went forthwith first in buying Greek books and then in clothes.[284] Later in the year, the prevalence of the Plague in Paris drove him to Orleans. He would have gone to Italy, but he had not the means. [285] In December he returned to Paris to continue his struggling life. [286] In a letter written in January, 1501, on the anniversary of his misfortune at Dover, he described himself ‘as having now for a whole year been sailing under a stormy sky against the waves and against the winds.’[287] To add to his troubles, the Plague again broke out in Paris; and, terrified by the number of funerals passing his door, the poor scholar fled from the city to spend a few weeks in his native country.[288] During his stay in Holland he visited the monastery at Stein,[289] where in early years he had tasted the bitters of the
  • 50. monastic life. Neither there nor elsewhere in Holland did he find a resting-place. Princess of Vere and Battus. Fortunately for him, one true friend at least turned up, willing and able to enter into sympathy with him. This was Battus, tutor to the Marchioness of Vere. Erasmus had already corresponded with him from Paris, pouring out his troubles to him, and declaring that he had no other hope but in him alone.[290] Kept away from Paris by the Plague, and finding not even a temporary home in Holland, he at last found a refuge for a while from his fears and cares in a visit to the castle of Tornahens,[291] the residence of the Marchioness of Vere and of Battus. It had the additional attraction of being near to St. Omer, where lived a former patron of Erasmus, the Abbot of St. Bertin. Erasmus would like to visit Colet again. Whilst staying with Battus he wrote to a friend, that he sometimes thought of returning to England to spend a month or two more with Colet, in order to confer further with him on some theological questions. He knew well, he said, how much good he should gain from doing so, but he could not get over the unlucky experience of his last voyage. As to his journey to Italy, that, too, was knocked on the head. He told his friend that he longed to visit Italy as ardently as ever, but it was out of the question; for, according to the adage of Plautus, ‘Sine pennis volare haud facile est.’[292] Writes his ‘Enchiridio n.’ Battus also wrote to Lord Mountjoy to tell him with what pleasure he had embraced Erasmus, but, ‘alas, how ill-treated and spoiled!’ He
  • 51. told him how he had been commiserating Erasmus on his ill-fortune in England, and how the philosopher had smiled and bade him put a good face on it, He did not regret having visited England; he cared more for the friends he had found in England than for all the gold of Crœsus. Battus concluded by telling Lord Mountjoy how Erasmus had described to him the courtesy of the Prior Charnock, the learning of Colet, the good nature of More, the virtues of his noble patron.[293] It was during this visit to St. Omer, in the summer of 1501, that Erasmus wrote his ‘Enchiridion.’ There happened to be staying in the castle a lady, a friend of Battus, who had a bad husband. The latter, whilst holding other divines at arm’s length, took to Erasmus. The wife, thinking that he possibly might have some influence over her husband, begged him, without betraying that it was at her instigation, to write something which might produce in him some religious impressions.[294] The ‘Enchiridion’ was the result, of which more will be said by and by. John Vitrarius. It was at St. Omer also that Erasmus became acquainted with John Vitrarius—a second John Colet in the earnestness of his Christian zeal against the corruptions of the church and vices of the clergy, in his love for St. Paul, in his outspoken preaching, and even in his manner of preaching, in his dislike of the Scholastic subtlety of Scotus, and even in his preference for Ambrose, Cyprian, Jerome, and Origen over Augustine. Erasmus ever afterwards linked the names of Colet and Vitrarius together, and admitted them both deservedly into his calendar of uncanonised saints.[295] The ‘Enchiridion’ was submitted to the judgment of Vitrarius, and obtained his approval.[296] Return of Erasmus to Paris. After many refreshing days passed at St. Omer, Erasmus returned to Paris to pursue his literary labours. These, notwithstanding all the
  • 52. hindrances of ill-health and poverty, never seemed to have flagged. [297] He had already made up his mind to devote himself to the Herculean task of correcting the text of St. Jerome’s voluminous works, with a view to their publication.[298] The first edition of his ‘Adagia’ had been printed in 1501; and during a visit to Louvain and Antwerp, in 1503, he was able to publish some other works—his afterwards famous ‘Enchiridion’ amongst the rest.[299] But notwithstanding all his indomitable energy, and the often repeated kindness of Battus and the Marchioness, it would be difficult to imagine a longer catalogue of troubles and disappointments—and these too of that harassing and vexatious kind which are most trying to the temper—than is contained in the letters of Erasmus during these dreary years.[300] He might well have been excused if, lost sight of as it would seem by his English friends, he had himself forgotten his promise to Colet on leaving Oxford, amidst the cares of his continental life. Erasmus remembers his promise to Colet. But whilst these necessities not a little interrupted, as was likely, those studies to which Colet’s example and precept had urged him, and lengthened out the preliminary labours which Erasmus had made up his mind must precede his active participation in Colet’s work, they did not, it seems, damp his energy, or induce him to look back after putting his hand to the plough. This and more lies touchingly hinted in the following letter written by Erasmus to Colet on receipt of the news of the elevation of his friend to the dignity of Doctor and Dean. Erasmus to Colet.[301] ‘If our friendship, most learned Colet, had been of a common-place kind, or your habits those of the common run of men, I should indeed have been somewhat fearful
  • 53. lest it might have been extinguished, or at least cooled, by our long and wide separation.... But I prefer to believe that the cause of my having received no letter from you now for several years, lies rather in your press of business, or ignorance of my whereabouts, or even in myself, than in your forgetfulness of an old friend.... ‘I am much surprised that you have not yet given to the world any of your commentaries on St. Paul and the Gospels. I know your modesty, but surely you ought to conquer that, and print them for the public good. Erasmus congratulat es Colet on his preferment . Wants to devote himself to Scripture studies. Greek and Hebrew studies. ‘As to the title of Doctor and Dean, I do not so much congratulate you about these—for I know well they will bring you nothing but labour—as those for whose good you are to bear them. ‘I cannot tell you, dearest Colet, how, by hook and by crook, I struggle to devote myself to the study of sacred literature—how I regret everything which either delays me or detains me from it. But constant ill-fortune has prevented me from extricating myself from these hindrances. When in France, I determined that if I could not conquer these difficulties I would cast them aside, and
  • 54. that once freed from them, with my whole mind I would set to work at these sacred studies, and devote the rest of my life to them. Although three years before I had attempted something on St. Paul’s Epistle to the Romans, [302] and had completed four volumes at one pull, I was nevertheless prevented from going on with it, owing chiefly to the want of a better knowledge of Greek. Consequently, for nearly these three years past, I have buried myself in Greek literature; nor do I think the labour has been thrown away. I began also to dip into Hebrew, but, deterred by the strangeness of the words, I desisted, knowing that one man’s life and genius are not enough for too many things at a time. I have read through a good part of the works of Origen, under whose guidance I seemed really to get on, for he opened to me, as it were, the springs and the method of theological science. The ‘Enchiridio n.’ ‘I send you [herewith], as a little literary present, some lucubrations of mine. Among them is our discussion, when in England, on the Agony of Christ, but so altered that you will hardly know it again. Besides, your reply and my rejoinder to it could not be found. The “Enchiridion” I wrote to display neither genius nor eloquence, but simply for this—to counteract the vulgar error of those who think that religion consists in ceremonies, and in more than Jewish observances, while they neglect what really pertains to piety. I have tried to teach, as it were, the art of piety in the same way as others have laid down the rules of [military] discipline.... The rest were written against the grain, especially the “Pæan” and “Obsecratio,” which I wrote to please Battus and Anna, the Princess of Vere. As to the “Panegyric,”[303] it was so contrary to my taste, that I do not remember ever having written
  • 55. anything more reluctantly; for I saw that such a thing could not be done without adulation.... The ‘Adagia.’ Erasmus wants help from his friends. ‘I wrote, if you recollect, sometime past, about the 100 copies of the “Adagia” which I sent at my own expense into England, now three years ago. Grocyn wrote me word that he would arrange with the greatest fidelity and diligence that they should be sold according to my wish, and I do not doubt but that he has performed his promise, for he is the best and most honourable man that ever lived in England. Will you be so good as to aid me in this matter, so far as to advise and spur on those by whom you think the business ought to be settled? For one cannot doubt but that, in so long a time, the books must be sold; and the money must of necessity have come to somebody’s hand; and it is likely to be of more use to me now than ever before. For, by some means or other, I must contrive to have a few months entirely to myself, that I may extricate myself somehow from my labours in secular literature. This I trusted I could have done this winter, had not so many hopes proved illusive. Nor, indeed, “with a great sum can I obtain this freedom,” even for a few months. I entreat you, therefore, to do what you can to aid me, panting as I do eagerly after sacred studies, in disengaging myself from those [secular] studies which have now ceased to be pleasant to me. It would not do for me to beg of my friend, Lord Mountjoy, although it would not seem unreasonable or impertinent if, of his own good will, he had chosen to aid me, both on the ground of his habitual patronage of my studies, and also because
  • 56. the “Adagia” were undertaken at his suggestion, and inscribed with his name. I am ashamed of the first edition [of the “Adagia”] both on account of the blundering mistakes of the printers, which seem made almost on purpose, and because, urged on by others, I hurried over the work which had now begun to seem to me dry and poor after my study of the Greek authors. Consequently, another edition is resolved upon, in which the errors of both author and printer are to be corrected, and the work made as useful as possible to students. His Greek studies not thrown away. ‘Although, however, I may for a while be engaged upon an humble task, yet whilst thus working in the Garden of the Greeks, I am gathering much fruit by the way for the time to come, which may hereafter be of use to me in sacred studies. For I have learned this by experience, that without Greek one can do nothing in any branch of study; for it is one thing to conjecture, and quite another thing to judge—one thing to see with other people’s eyes, and quite another thing to believe what you see with your own. ‘But to what a length this letter has grown! Love, however, will excuse loquacity. Farewell, most learned and excellent Colet. ‘Pray let me know what has happened to our friend Sixtinus; also what your friend the Prior Richard Charnock is doing. ‘In order that whatever you may write or send to me may duly come to hand, be so good as to have them addressed to Christopher Fisher (a most loving friend and
  • 57. patron of all learned men, and you amongst the rest), in whose family I am now a guest.’ Paris, 1504 [in error for 1505]. Thus had the poor scholar worked on, for the most part in silence, during these years, struggling alone, yet manfully, in the midst of the manifold hindrances cast in his way by ill-health and straitened means, neither free-born (as his friend Colet was), and thus able to tread unencumbered the path of duty, nor finding himself able even ‘with a great sum to obtain freedom’ for a while. Yet through all had Erasmus kept courageously to the collar, steadily toiling on through five years of preliminary labours, with earnest purpose to redeem his promise to Colet—first, fully to equip himself with the proper tools and then, but not till then, to join him in fellow work. Why Colet had not written. Colet surely had forgotten the promise of Erasmus on leaving Oxford, or perchance the hope it held out was too slender for him to rest on, else he would hardly have left him during these years without letters of brotherly encouragement. It is true that Erasmus still confessed himself to be occupied in merely preliminary labours. His great work, no less than it had been five years before, was still in the future. Yet the fire caught from his contact with Colet at Oxford was at least flickering on the hearth, and with fresh stirring and fuel might perhaps after all be kindled into active flame. Colet’s reply to this letter has not come down to us, but from the result we may be sure that it contained a pressing invitation to revisit England, and the promise of a warm reception. VI. THE ‘ENCHIRIDION,’ ETC. OF ERASMUS (1501-5).
  • 58. In the meantime, closer inspection of the literary present sent by Erasmus, must have proved to Colet to how large an extent, after so long a process of study and digestion, his friend had really adopted the views which he himself had held and consistently preached for the last ten years. The ‘Enchiridio n.’ The ‘Enchiridion’ was, in truth, a re-echo of the very key-note of Colet’s faith. It openly taught, as Colet now for so many years had been teaching, that the true Christian’s religion, instead of consisting in the acceptance of scholastic dogmas, or the performance of outward rites and ceremonies, really consists in a true, self- sacrificing loyalty to Christ, his ever-living Prince; that life is a warfare, and that the Christian must sacrifice his evil lusts and passions, and spend his strength, not in the pursuit of his own pleasure, but in active service of his Prince;—such was the drift and spirit of this ‘Handybook of the Christian Soldier.’[304] It must not be assumed, however, that Erasmus had adopted all the views which Colet had expressed in their many conversations at Oxford. On the contrary, I think there may be traced in the ‘Enchiridion’[305] a tendency to interpret the text of Scripture allegorically, rather than to seek out its literal meaning—a tendency which must have been somewhat opposed to the strong convictions of Colet, and even to those of Erasmus, in after years. But he had just then been studying Origen, and it is not strange that he should for a while be fascinated, as so many others have been, by the allegorical method of interpretation adopted by that father. He had learned so much from his writings, that he yielded the more readily perhaps in this particular to the force of Origen’s rich imagination. [306] Not a success at first.
  • 59. 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! textbookfull.com