0% found this document useful (0 votes)
48 views

PDF Stylish F# 6: Crafting Elegant Functional Code for .NET 6 Kit Eason download

The document promotes the ebook 'Stylish F# 6: Crafting Elegant Functional Code for .NET 6' by Kit Eason, available for download on ebookmeta.com. It includes links to additional recommended digital products related to programming and software development. The document also contains copyright information and details about the book's content and structure.

Uploaded by

zamotpapack3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

PDF Stylish F# 6: Crafting Elegant Functional Code for .NET 6 Kit Eason download

The document promotes the ebook 'Stylish F# 6: Crafting Elegant Functional Code for .NET 6' by Kit Eason, available for download on ebookmeta.com. It includes links to additional recommended digital products related to programming and software development. The document also contains copyright information and details about the book's content and structure.

Uploaded by

zamotpapack3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Get the full ebook with Bonus Features for a Better Reading Experience on ebookmeta.

com

Stylish F# 6: Crafting Elegant Functional Code for


.NET 6 Kit Eason

https://ebookmeta.com/product/stylish-f-6-crafting-elegant-
functional-code-for-net-6-kit-eason/

OR CLICK HERE

DOWLOAD NOW

Download more ebook instantly today at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

ASP NET Core 6 Succinctly Dirk Strauss

https://ebookmeta.com/product/asp-net-core-6-succinctly-dirk-strauss/

ebookmeta.com

Effective Go: Elegant, Efficient, and Testable Code (MEAP


Version 3) 1 / chapter 1 to 6 of 8 Edition Inanc Gumus

https://ebookmeta.com/product/effective-go-elegant-efficient-and-
testable-code-meap-version-3-1-chapter-1-to-6-of-8-edition-inanc-
gumus/
ebookmeta.com

The easiest way to learn design patterns With C code


samples using NET 6 templates Fiodar Sazanavets

https://ebookmeta.com/product/the-easiest-way-to-learn-design-
patterns-with-c-code-samples-using-net-6-templates-fiodar-sazanavets/

ebookmeta.com

An Introduction to Programming Languages: Simultaneous


Learning in Multiple Coding Environments 1st Edition Paul
A. Gagniuc
https://ebookmeta.com/product/an-introduction-to-programming-
languages-simultaneous-learning-in-multiple-coding-environments-1st-
edition-paul-a-gagniuc/
ebookmeta.com
Five Dates Between Friends 1st Edition Erin Thomson

https://ebookmeta.com/product/five-dates-between-friends-1st-edition-
erin-thomson/

ebookmeta.com

Bring the War Home The White Power Movement and


Paramilitary America First Edition Kathleen Belew

https://ebookmeta.com/product/bring-the-war-home-the-white-power-
movement-and-paramilitary-america-first-edition-kathleen-belew/

ebookmeta.com

The Green Hedge Witch 2nd Edition Rae Beth

https://ebookmeta.com/product/the-green-hedge-witch-2nd-edition-rae-
beth/

ebookmeta.com

Sorrentino's Canadian Textbook for the Support Worker Mary


J. Wilk

https://ebookmeta.com/product/sorrentinos-canadian-textbook-for-the-
support-worker-mary-j-wilk/

ebookmeta.com

Writing Research Proposals for Social Sciences and


Humanities in a Higher Education Context 1st Edition
George Damaskinidis
https://ebookmeta.com/product/writing-research-proposals-for-social-
sciences-and-humanities-in-a-higher-education-context-1st-edition-
george-damaskinidis/
ebookmeta.com
Essential Astrophysics: Interstellar Medium to Stellar
Remnants 1st Edition Shantanu Basu

https://ebookmeta.com/product/essential-astrophysics-interstellar-
medium-to-stellar-remnants-1st-edition-shantanu-basu/

ebookmeta.com
Stylish
F# 6
Crafting Elegant Functional Code
for .NET 6

Second Edition

Kit Eason
Stylish F# 6
Crafting Elegant Functional
Code for .NET 6
Second Edition

Kit Eason
Stylish F# 6: Crafting Elegant Functional Code for .NET 6
Kit Eason
Farnham, Surrey, UK

ISBN-13 (pbk): 978-1-4842-7204-6 ISBN-13 (electronic): 978-1-4842-7205-3


https://doi.org/10.1007/978-1-4842-7205-3

Copyright © 2022 by Kit Eason


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Joan Murray
Development Editor: Laura Berendson
Coordinating Editor: Jill Balzano
Cover image designed by Kit Eason, based on data courtesy of NYC Open Data
Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York Plaza, Suite
4600, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.
com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner)
is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware
corporation.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/9781484272046. For more
detailed information, please visit http://www.apress.com/source-­code.
Printed on acid-free paper
To Val, Matt, Meg, Kate, Andy, Noah, and Darwin:
my own persistent collection.
Table of Contents
About the Author�����������������������������������������������������������������������������������������������������xv

About the Technical Reviewer�������������������������������������������������������������������������������xvii


Acknowledgments��������������������������������������������������������������������������������������������������xix

Introduction������������������������������������������������������������������������������������������������������������xxi

Chapter 1: The Sense of Style����������������������������������������������������������������������������������� 1


Why a Style Guide?����������������������������������������������������������������������������������������������������������������������� 1
Understanding Beats Obedience��������������������������������������������������������������������������������������������������� 2
Good Guidance from Bad Code����������������������������������������������������������������������������������������������������� 2
What About Testability?����������������������������������������������������������������������������������������������������������������� 8
Complexity Explosions������������������������������������������������������������������������������������������������������������������ 8
Summary�������������������������������������������������������������������������������������������������������������������������������������� 9

Chapter 2: Designing Functions Using Types���������������������������������������������������������� 11


Miles and Yards (No, Really!)������������������������������������������������������������������������������������������������������� 11
Converting Miles and Yards to Decimal Miles����������������������������������������������������������������������� 12
How to Design a Function����������������������������������������������������������������������������������������������������������� 13
Sketch the Signature of the Function������������������������������������������������������������������������������������ 14
Naively Code the Body of the Function���������������������������������������������������������������������������������� 14
Review the Signature for Type Safety������������������������������������������������������������������������������������ 15
Review and Refine����������������������������������������������������������������������������������������������������������������� 19
A Final Polish������������������������������������������������������������������������������������������������������������������������������ 21
Recommendations���������������������������������������������������������������������������������������������������������������������� 23
Summary������������������������������������������������������������������������������������������������������������������������������������ 24
Exercises������������������������������������������������������������������������������������������������������������������������������������� 24
Exercise Solutions����������������������������������������������������������������������������������������������������������������������� 25

v
Table of Contents

Chapter 3: Missing Data����������������������������������������������������������������������������������������� 29


A Brief History of Null������������������������������������������������������������������������������������������������������������������ 29
Option Types vs. Null������������������������������������������������������������������������������������������������������������������� 32
Consuming Option Types������������������������������������������������������������������������������������������������������������� 34
Pattern Matching on Option Types����������������������������������������������������������������������������������������� 35
The Option Module���������������������������������������������������������������������������������������������������������������� 36
Option Type No-Nos��������������������������������������������������������������������������������������������������������������������� 43
Designing Out Missing Data�������������������������������������������������������������������������������������������������������� 44
Interoperating with the Nullable World��������������������������������������������������������������������������������������� 48
Leaking In of Null Values������������������������������������������������������������������������������������������������������� 48
Defining a SafeString Type���������������������������������������������������������������������������������������������������� 49
Using Option.ofObj����������������������������������������������������������������������������������������������������������������� 50
Using Option.ofNullable��������������������������������������������������������������������������������������������������������� 51
Leaking Option Types and DUs Out���������������������������������������������������������������������������������������� 52
Using Option.toObj����������������������������������������������������������������������������������������������������������������� 52
Using Option.toNullable��������������������������������������������������������������������������������������������������������� 53
The Future of Null������������������������������������������������������������������������������������������������������������������ 54
The ValueOption Type������������������������������������������������������������������������������������������������������������������ 55
Recommendations���������������������������������������������������������������������������������������������������������������������� 56
Summary������������������������������������������������������������������������������������������������������������������������������������ 56
Exercises������������������������������������������������������������������������������������������������������������������������������������� 57
Exercise Solutions����������������������������������������������������������������������������������������������������������������������� 58

Chapter 4: Working Effectively with Collection Functions�������������������������������������� 61


Anatomy of a Collection Function����������������������������������������������������������������������������������������������� 61
Picking the Right Collection Function����������������������������������������������������������������������������������������� 64
Detailed Collection Function Tables�������������������������������������������������������������������������������������������� 66
Practicing with Collection Functions������������������������������������������������������������������������������������������� 72
Exercise Setup����������������������������������������������������������������������������������������������������������������������� 72
Single Collection Function Exercises������������������������������������������������������������������������������������� 73
Multiple Collection Function Exercises���������������������������������������������������������������������������������� 77

vi
Table of Contents

Partial Functions������������������������������������������������������������������������������������������������������������������������� 80
Coding Around Partial Functions������������������������������������������������������������������������������������������� 82
Using the “try” Idiom for Partial Functions���������������������������������������������������������������������������� 84
Consuming Values from try… Functions������������������������������������������������������������������������������� 86
Try… Function Exercises������������������������������������������������������������������������������������������������������������ 86
Functions for Other Kinds of Collections������������������������������������������������������������������������������������� 87
When the Collection Function Is Missing������������������������������������������������������������������������������������ 88
Common Mistakes���������������������������������������������������������������������������������������������������������������������� 89
Recommendations���������������������������������������������������������������������������������������������������������������������� 93
Summary������������������������������������������������������������������������������������������������������������������������������������ 94
Exercise Solutions����������������������������������������������������������������������������������������������������������������������� 94

Chapter 5: Immutability and Mutation������������������������������������������������������������������� 99


These Folks Are Crazy!���������������������������������������������������������������������������������������������������������������� 99
Classic Mutable Style������������������������������������������������������������������������������������������������������������������ 99
Immutability Basics������������������������������������������������������������������������������������������������������������������� 101
Common Mutable Patterns������������������������������������������������������������������������������������������������������� 103
Linear Search���������������������������������������������������������������������������������������������������������������������� 104
Guarded Linear Search�������������������������������������������������������������������������������������������������������� 105
Process All Items����������������������������������������������������������������������������������������������������������������� 107
Repeat Until������������������������������������������������������������������������������������������������������������������������� 110
Find Extreme Value�������������������������������������������������������������������������������������������������������������� 112
Summarize a Collection������������������������������������������������������������������������������������������������������� 115
Recommendations�������������������������������������������������������������������������������������������������������������������� 117
Summary���������������������������������������������������������������������������������������������������������������������������������� 118
Exercises����������������������������������������������������������������������������������������������������������������������������������� 118
Exercise Solutions��������������������������������������������������������������������������������������������������������������������� 119

Chapter 6: Pattern Matching�������������������������������������������������������������������������������� 123


Weaving Software with Patterns����������������������������������������������������������������������������������������������� 123
Pattern Matching Basics����������������������������������������������������������������������������������������������������������� 123
When Guards����������������������������������������������������������������������������������������������������������������������������� 126
vii
Table of Contents

Pattern Matching on Arrays and Lists��������������������������������������������������������������������������������������� 127


Pattern Matching on Tuples������������������������������������������������������������������������������������������������������ 129
Pattern Matching on Records��������������������������������������������������������������������������������������������������� 130
Pattern Matching on Discriminated Unions������������������������������������������������������������������������������ 133
Pattern Matching on DUs in Function Parameters�������������������������������������������������������������������� 135
Pattern Matching in Let Bindings���������������������������������������������������������������������������������������������� 138
Revisiting Single-Case Discriminated Unions��������������������������������������������������������������������������� 139
Pattern Matching in Loops and Lambdas��������������������������������������������������������������������������������� 141
Pattern Matching and Enums���������������������������������������������������������������������������������������������������� 142
Active Patterns�������������������������������������������������������������������������������������������������������������������������� 144
Single-Case Active Patterns������������������������������������������������������������������������������������������������ 144
Multicase Active Patterns���������������������������������������������������������������������������������������������������� 146
Partial Active Patterns��������������������������������������������������������������������������������������������������������� 147
Parameterized Active Patterns�������������������������������������������������������������������������������������������� 149
Pattern Matching with “&”�������������������������������������������������������������������������������������������������������� 150
Pattern Matching on Types�������������������������������������������������������������������������������������������������������� 151
Pattern Matching on Null���������������������������������������������������������������������������������������������������������� 153
Recommendations�������������������������������������������������������������������������������������������������������������������� 154
Summary���������������������������������������������������������������������������������������������������������������������������������� 156
Exercises����������������������������������������������������������������������������������������������������������������������������������� 157
Exercise Solutions��������������������������������������������������������������������������������������������������������������������� 160

Chapter 7: Record Types��������������������������������������������������������������������������������������� 165


Winning with Records��������������������������������������������������������������������������������������������������������������� 165
Record Type Basics������������������������������������������������������������������������������������������������������������������� 165
Record Types and Immutability������������������������������������������������������������������������������������������������� 167
Default Constructors, Setters, and Getters�������������������������������������������������������������������������������� 169
Records vs. Classes������������������������������������������������������������������������������������������������������������������ 169
Structural Equality by Default���������������������������������������������������������������������������������������������� 170
Records as Structs�������������������������������������������������������������������������������������������������������������� 173
Mapping from Instantiation Values to Members������������������������������������������������������������������ 175

viii
Table of Contents

Records Everywhere?��������������������������������������������������������������������������������������������������������������� 176


Pushing Records to the Limit���������������������������������������������������������������������������������������������������� 177
Generic Records������������������������������������������������������������������������������������������������������������������ 178
Recursive Records��������������������������������������������������������������������������������������������������������������� 179
Records with Methods��������������������������������������������������������������������������������������������������������� 180
Records with Methods – A Good Idea?�������������������������������������������������������������������������������� 183
Anonymous Records����������������������������������������������������������������������������������������������������������������� 184
Anonymous and Named Record Terminology���������������������������������������������������������������������� 186
Anonymous Records and Comparison��������������������������������������������������������������������������������� 186
“Copy and Update” on Anonymous Records������������������������������������������������������������������������ 189
Serialization and Deserialization of Anonymous Records��������������������������������������������������� 190
Anonymous Records in Type Hints�������������������������������������������������������������������������������������� 192
Struct Anonymous Records������������������������������������������������������������������������������������������������� 192
Anonymous Records and C#������������������������������������������������������������������������������������������������ 193
Pattern Matching on Anonymous Records�������������������������������������������������������������������������� 193
Adding Methods to Anonymous Records����������������������������������������������������������������������������� 194
Mutation and Anonymous Records�������������������������������������������������������������������������������������� 194
Record Layout��������������������������������������������������������������������������������������������������������������������������� 195
Recommendations�������������������������������������������������������������������������������������������������������������������� 196
Summary���������������������������������������������������������������������������������������������������������������������������������� 198
Exercises����������������������������������������������������������������������������������������������������������������������������������� 198
Exercise Solutions��������������������������������������������������������������������������������������������������������������������� 200

Chapter 8: Classes������������������������������������������������������������������������������������������������ 205


The Power of Classes���������������������������������������������������������������������������������������������������������������� 205
Additional Constructors������������������������������������������������������������������������������������������������������������� 215
Values As Members������������������������������������������������������������������������������������������������������������������� 217
Simple Mutable Properties�������������������������������������������������������������������������������������������������������� 219
Member Getters and Setters with Bodies��������������������������������������������������������������������������������� 220
Named Parameters and Object Initialization Syntax����������������������������������������������������������������� 222
Indexed Properties�������������������������������������������������������������������������������������������������������������������� 223

ix
Table of Contents

Interfaces���������������������������������������������������������������������������������������������������������������������������������� 226
Object Expressions�������������������������������������������������������������������������������������������������������������������� 232
Abstract Classes����������������������������������������������������������������������������������������������������������������������� 235
Abstract Members��������������������������������������������������������������������������������������������������������������� 235
Default Member Implementations��������������������������������������������������������������������������������������� 236
Class Equality and Comparison������������������������������������������������������������������������������������������������� 237
Implementing Equality��������������������������������������������������������������������������������������������������������� 237
Implementing Comparison�������������������������������������������������������������������������������������������������� 243
Recommendations�������������������������������������������������������������������������������������������������������������������� 246
Summary���������������������������������������������������������������������������������������������������������������������������������� 246
Exercises����������������������������������������������������������������������������������������������������������������������������������� 248
Exercise Solutions��������������������������������������������������������������������������������������������������������������������� 249

Chapter 9: Programming with Functions�������������������������������������������������������������� 253


Functions First�������������������������������������������������������������������������������������������������������������������������� 253
Functions as Values������������������������������������������������������������������������������������������������������������������ 253
Currying and Partial Application����������������������������������������������������������������������������������������������� 255
Mixing Tupled and Curried Styles���������������������������������������������������������������������������������������������� 257
Function Signatures Revisited�������������������������������������������������������������������������������������������������� 259
Type Hints for Functions����������������������������������������������������������������������������������������������������������� 260
Functions That Return Functions���������������������������������������������������������������������������������������������� 262
Function Composition��������������������������������������������������������������������������������������������������������������� 265
Recommendations�������������������������������������������������������������������������������������������������������������������� 268
Summary���������������������������������������������������������������������������������������������������������������������������������� 269
Exercises����������������������������������������������������������������������������������������������������������������������������������� 269
Exercise Solutions��������������������������������������������������������������������������������������������������������������������� 272

Chapter 10: Asynchronous and Parallel Programming����������������������������������������� 275


Ordering Pizza��������������������������������������������������������������������������������������������������������������������������� 275
A World Without Async�������������������������������������������������������������������������������������������������������������� 276
Running the Synchronous Downloader������������������������������������������������������������������������������������� 282
Converting Code to Asynchronous�������������������������������������������������������������������������������������������� 284
x
Table of Contents

Locking Shared Resources������������������������������������������������������������������������������������������������������� 290


Testing Asynchronous Downloads�������������������������������������������������������������������������������������������� 291
Batching������������������������������������������������������������������������������������������������������������������������������������ 292
Throttling����������������������������������������������������������������������������������������������������������������������������������� 297
C# Task vs. F# Async����������������������������������������������������������������������������������������������������������������� 299
F# Tasks������������������������������������������������������������������������������������������������������������������������������������ 301
Recommendations�������������������������������������������������������������������������������������������������������������������� 304
Summary���������������������������������������������������������������������������������������������������������������������������������� 305
Exercises����������������������������������������������������������������������������������������������������������������������������������� 306
Exercise Solutions��������������������������������������������������������������������������������������������������������������������� 307

Chapter 11: Railway Oriented Programming�������������������������������������������������������� 311


Going Off the Rails�������������������������������������������������������������������������������������������������������������������� 311
On the Factory Floor������������������������������������������������������������������������������������������������������������������ 312
Adapting Functions for Failure�������������������������������������������������������������������������������������������������� 316
Writing a Bypass Adapter���������������������������������������������������������������������������������������������������������� 317
Writing a Pass-Through Adapter����������������������������������������������������������������������������������������������� 318
Building the Production Line����������������������������������������������������������������������������������������������������� 319
Making It Official����������������������������������������������������������������������������������������������������������������������� 323
Love Your Errors������������������������������������������������������������������������������������������������������������������������ 324
Recommendations�������������������������������������������������������������������������������������������������������������������� 328
Summary���������������������������������������������������������������������������������������������������������������������������������� 329
Exercises����������������������������������������������������������������������������������������������������������������������������������� 330
Exercise Solutions��������������������������������������������������������������������������������������������������������������������� 333

Chapter 12: Performance�������������������������������������������������������������������������������������� 337


Design Is Compromise�������������������������������������������������������������������������������������������������������������� 337
Some Case Studies������������������������������������������������������������������������������������������������������������������� 338
BenchmarkDotNet��������������������������������������������������������������������������������������������������������������������� 338
Case Study: Inappropriate Collection Types������������������������������������������������������������������������������ 340
Avoiding Indexed Access to Lists���������������������������������������������������������������������������������������� 343

xi
Table of Contents

Using Arrays Instead of Lists����������������������������������������������������������������������������������������������� 345


Use Sequences Instead of Arrays���������������������������������������������������������������������������������������� 346
Avoiding Collection Functions��������������������������������������������������������������������������������������������� 347
Avoiding Loops Having Skips����������������������������������������������������������������������������������������������� 349
Inappropriate Collection Types – Summary������������������������������������������������������������������������� 350
Case Study: Short-Term Objects����������������������������������������������������������������������������������������������� 352
Sequences Instead of Arrays����������������������������������������������������������������������������������������������� 355
Avoiding Object Creation����������������������������������������������������������������������������������������������������� 356
Reducing Tuples������������������������������������������������������������������������������������������������������������������ 357
Using Struct Tuples�������������������������������������������������������������������������������������������������������������� 358
Operator Choice������������������������������������������������������������������������������������������������������������������� 360
Short-Term Objects – Summary������������������������������������������������������������������������������������������ 362
Case Study: Naive String Building��������������������������������������������������������������������������������������������� 364
StringBuilder to the Rescue������������������������������������������������������������������������������������������������� 366
Using String.Join����������������������������������������������������������������������������������������������������������������� 367
Using Array.Parallel.map������������������������������������������������������������������������������������������������������ 368
Using String Interpolation���������������������������������������������������������������������������������������������������� 370
Naive String Building – Summary��������������������������������������������������������������������������������������� 371
Other Common Performance Issues����������������������������������������������������������������������������������������� 372
Searching Large Collections������������������������������������������������������������������������������������������������ 372
Comparison Operators and DateTimes�������������������������������������������������������������������������������� 372
Concatenating Lists������������������������������������������������������������������������������������������������������������� 372
For-Loop with Unexpected List Creation������������������������������������������������������������������������������ 372
F# and Span Support���������������������������������������������������������������������������������������������������������������� 373
The Importance of Tests������������������������������������������������������������������������������������������������������������ 373
Recommendations�������������������������������������������������������������������������������������������������������������������� 375
Summary���������������������������������������������������������������������������������������������������������������������������������� 376
Exercises����������������������������������������������������������������������������������������������������������������������������������� 377
Exercise Solutions��������������������������������������������������������������������������������������������������������������������� 380

xii
Table of Contents

Chapter 13: Layout and Naming��������������������������������������������������������������������������� 383


Where Are My Braces?�������������������������������������������������������������������������������������������������������������� 383
It’s Okay Pluto, I’m Not a Planet Either�������������������������������������������������������������������������������������� 384
Some Infelicitous Code������������������������������������������������������������������������������������������������������������� 386
Convenience Functions������������������������������������������������������������������������������������������������������������� 390
Column Extraction Functions���������������������������������������������������������������������������������������������������� 391
The Observation Range Type����������������������������������������������������������������������������������������������������� 393
The Importance of Alignment���������������������������������������������������������������������������������������������������� 395
The Minor Planet Type��������������������������������������������������������������������������������������������������������������� 397
Recommendations�������������������������������������������������������������������������������������������������������������������� 404
Summary���������������������������������������������������������������������������������������������������������������������������������� 405
Exercise������������������������������������������������������������������������������������������������������������������������������������ 406
Exercise Solution���������������������������������������������������������������������������������������������������������������������� 407

Chapter 14: Summary������������������������������������������������������������������������������������������� 409


F# and the Sense of Style��������������������������������������������������������������������������������������������������������� 409
Designing Functions with Types������������������������������������������������������������������������������������������������ 409
Missing Data����������������������������������������������������������������������������������������������������������������������������� 410
Collection Functions������������������������������������������������������������������������������������������������������������������ 410
Immutability and Mutation�������������������������������������������������������������������������������������������������������� 411
Pattern Matching���������������������������������������������������������������������������������������������������������������������� 411
Record Types����������������������������������������������������������������������������������������������������������������������������� 411
Classes�������������������������������������������������������������������������������������������������������������������������������������� 412
Programming with Functions���������������������������������������������������������������������������������������������������� 412
Asynchronous and Parallel Programming��������������������������������������������������������������������������������� 413
Railway Oriented Programming������������������������������������������������������������������������������������������������ 414
Performance����������������������������������������������������������������������������������������������������������������������������� 414
Layout and Naming������������������������������������������������������������������������������������������������������������������� 415
Onward!������������������������������������������������������������������������������������������������������������������������������������ 416

Index��������������������������������������������������������������������������������������������������������������������� 417

xiii
About the Author
Kit Eason is a software developer and educator with more than 20 years of experience.
He has been programming in F# since 2011 and is employed at Perpetuum Ltd., working
on an extensive network of energy-harvesting vibration sensors fitted to railway rolling
stock and infrastructure. Kit is an avid F# user who is passionate about teaching others.
He has contributed to several publications, including the Apress book “Beginning F#.”
He often teaches on the topic of F#, and his popular videos appear on Udemy and
Pluralsight.

xv
About the Technical Reviewer
Stachu Korick stumbled upon F# in 2014 and instantly
fell in love with both the language and the surrounding
community. Most importantly, he met his wife Olya after
speaking on F# at a local .NET conference near Philadelphia.
As time allows, he works on an F# podcast WTF# (https://
wtfsharp.com). Beyond software, Stachu spends his time as
an amateur woodworker, playing with his cats, practicing
chemistry, or jotting down bits of lyrics to eventually
compose into music.

xvii
Another Random Scribd Document
with Unrelated Content
But Richelieu went too far. Some days later, D’Argenson wrote in
his journal: “M. de Richelieu is too much attached to the trifles of the
ballet theatre. They say he has behaved like a fool; he was too open
in his antagonism to the mistress, and she has regained the upper
hand. People consider her to count for as much or more than
Cardinal Fleury in the government. Woe to any one who dares to pit
himself against her at present! She unites pleasure to decision, and
the suffrages of the principal ministers to the force of habit which is
constantly gaining strength in a mild and affectionate monarch. But
woe to the state governed in this way by a coquette! People are
exclaiming on all hands. It is kicking against the pricks to revolt in
any wise against her. Richelieu has found that out; he ought to give
up this trifling business of the ballet stage in order to pursue greater,
more important, and more virtuous matters. It would have been
enough for him to absent himself from these operas and to do so
from pride, as soon as his charge was injuriously affected by them.
The instructions he gave the musicians were thus worded: ‘Such a
person will be present at such an hour to play in Madame de
Pompadour’s opera.’ He was worsted at every step. The real friends
of those who made any pretensions advised them strongly to make
their way by means of Madame the Marquise; homage must be paid
to her.”
Like the majority of men too much favored by women, Richelieu
resembled a spoiled child. He was stingy, proud, and wilful. However,
he ended by yielding. When this quarrel of etiquette was at its
height, Louis XV. carelessly asked him this simple question:
“Richelieu, how many times have you been at the Bastille?”—“Three
times,” responded the audacious courtier. But he promised himself
not to go a fourth time. He submitted, therefore, and the Duke de La
Vallière, who remained director of the troupe, was rewarded for his
patience by the blue ribbon.
The third theatrical season ended March 22, 1749; it had cost at
least a hundred thousand ecus. Louis XV., who was not always
prodigal, began to find the expenses excessive. He did not get his
money’s worth in amusement. The fourth and last theatrical season
of the little cabinets lasted from December 26, 1749, to April 27,
1750.
Madame de Pompadour had successfully attempted comedy,
opera, and ballet. She wanted to add another gem to her crown.
After Thalia, Euterpe, and Terpsichore, it was now the turn of
Melpomene. February 28, 1750, the Marquise played the part of
Alzire. Voltaire, enraptured, went to thank her for her interpretation
of his work, as she was at her toilette, and addressed her in this not
very original impromptu:—
“Cette Américaine parfaite
Trop de larmes a fait couler.
Ne pourrai-je me consoler
Et voir Venus à sa toilette?”[34]

The King began to be bored by these incessant spectacles. He


decided that there should be no more comedies, ballets, music, and
dancing at Versailles, and that hereafter the representations should
take place at the Château of Bellevue. The stage of this château was
very small, and did not admit of a brilliant mise en scène. The
number of spectators had to be greatly restricted. Accustomed to a
real theatre, splendid decorations, and a numerous audience, the
actors and actresses no longer showed the same enthusiasm. The
hour of decadence had come. However, Jean Jacques Rousseau’s
Devin du Village was very successfully played in 1753. Madame de
Pompadour took the part of Colette. The next day she sent fifty louis
to Jean Jacques, who thanked her in the following letter:—
“Paris, March 7, 1753.—Madame: In accepting this present, which
has been sent me by you, I believe I have testified my respect for
the hand from which it came, and I venture to add that of the two
proofs you have made of my moderation, interest is not the most
dangerous. I am with respect, etc.”
The Devin du Village was the Swan Song. Madame de Pompadour
no longer pleased Louis XV. as an actress. Hence she closed the
Bellevue theatre, and her ambition became, if not to amuse, at least
to interest, as a political woman, the master whose mistress she was
said to be.
V
THE GRANDEURS OF THE MARQUISE DE POMPADOUR

L
ouis XV. had made his mistress what one might call a vice-queen.
She had the power, luxury, riches, and adulations of royalty;
everything, in fact, except its moral prestige. Surrounded by a court
of ministers, prelates, and nobles, she throned it in the midst of
pomp and opulence. She was the type of the woman à la mode,
elegant, coquettish, absolute, always on show, insatiable for praise
and success, thirsting for dignities, pleasures, and money; playing
not merely the great lady, but the sovereign, having her courtiers,
her creatures, her poets, reigning alike over the King and the
kingdom.
M. Arsène Houssaye has said with justice: “Louis XV. had three
prime ministers: Cardinal Fleury, the Duke de Choiseul, the Marquise
de Pompadour.” But the Marquise was not an ordinary prime
minister; she was a prime minister doubled with a mistress. To a
woman invested with this exaggerated rôle, a display of power was
necessary. The favorite set herself to create around her a sort of
decorum, etiquette, and factitious grandeur. Like little women who
wear enormously high heels, she made herself a pedestal. Madame
d’Étioles had disappeared; nothing remained but the Marquise de
Pompadour. To be a marchioness did not satisfy her, and she
demanded and obtained the tabouret and the honors of a duchess.
She had a box at the court theatre with a grating behind which she
shut herself up tête-à-tête with the King. In the chapel a gallery in
the grand tribune was reserved for her and her suite. People waited
on her stairway at the hour of her toilette just as they await a
ministerial audience in an ante-chamber. She used to say to the
ministers: “Continue; I am satisfied with you,” and to the foreign
ambassadors: “Observe that on Tuesdays the King cannot see you,
gentlemen, for I think you will hardly follow us to Compiègne.”
One of the cabinets in her apartment was full of petitions.
Solicitors approached her with respectful fear. The ducal mantle and
velvet cap figured on the panels of her carriages. A nobleman
carried her mantle and awaited her coming in the ante-chamber. A
man of illustrious birth, a Chevalier d’Hénen, of the family of the
Princes de Chimay, rode at her carriage door as equerry. She was
served at table by a Chevalier of Saint Louis, her steward Colin, a
napkin under his arm. Her chambermaid was a woman of quality,
Madame du Hausset, who has left such curious Memoirs. The all-
powerful favorite had not forgotten her family. Her father was
ennobled in 1747. Her brother, Abel Poisson, became successively
Marquis de Vandières, Marquis de Marigny, Marquis de Ménars. The
marquisate not contenting him, he obtained a place created for
Colbert, that of superintendent of crown buildings. He was as a
patron of artists a Mecænas, an arbiter elegantiarum. The King, who
treated him as his brother-in-law, gave him the blue ribbon and put
him on an equality with the greatest nobles of the realm. Young
Alexandrine, the daughter of Madame de Pompadour and M. de
Étioles, was brought up at Paris in the convent of the Assumption.
The nuns showed her the greatest attention. She was addressed
by her baptismal name, as was then the custom for princesses of the
blood, and she was expected to make one of the most brilliant
marriages in France. Madame de Pompadour desired pomp even in
death. She bought a splendid sepulchre in the Capuchin convent in
the Place Vendôme, Paris, from the Trémoille family. There she built
a magnificent mausoleum, where her mother was interred and
where she reserved a place for herself.[35]
The favorite had not simply power, but beauty; beauty, that
supreme weapon. A veritable magician, she transformed herself at
will. As mobile as the clouds, as changeful as the wave, she renewed
and metamorphosed herself incessantly. No actress knew better than
she how to compose an attitude or a countenance. In her whole
person there was an exquisite grace, an exceptional charm, a taste,
an elegance which amounted to subtlety. La Tour, the pastel painter,
is he who has best reproduced her animated, spirituelle, triumphant
physiognomy, the eyes full of intelligence and audacity, the satin
skin, the supple figure, the general harmony, the charming and
coquettish whole.
All the splendors of luxury were like a frame to the picture. A new
Danaë, the Marquise disappeared under a shower of gold. It is
known exactly what she cost France from September 9, 1745, the
time when her favor began, until April 15, 1764, the day of her
death. M. Le Roy has discovered an authentic document,[36]
containing an account of the favorite’s expenses during this period of
nearly twenty years. The total is 35,924,140 livres. In this list of
expenses is found the pension granted to Madame Lebon for having
predicted to the Marquise, then only nine years old, that she would
one day be the mistress of Louis XV.
Nothing seemed fine enough for Madame de Pompadour, either in
dress, lodgings, or furniture. At Versailles she secured for herself on
the ground floor, on the terrace looking toward the parterre on the
north, the magnificent apartments occupied by the Duke and
Duchess de Penthièvre.[37] (Part of the ministry of foreign affairs is
established there at present. The minister’s study is the same as that
of Madame de Pompadour. Her bedchamber is now the thirteenth
hall of the marshals, her ante-chamber the hall of famous warriors.)
The favorite bought a superb house in the city communicating by
a passage with the apartments of the palace (it is now the hôtel des
Réservoirs). In 1748 she acquired the château of Ciécy and the
estate of Aunay, and in 1749 the château of La Celle, near Versailles.
In 1750 she inaugurated, on the hill commanding the Seine,
between Sèvres and Meudon, that enchanting abode of Bellevue,
where all the arts rivalled each other to create a magic entity. The
ante-chamber with statues by Adam and Falconnet; the dining-room
with paintings of game and fish by Oudry; the salon decorated by
Vanloo; the apartment of the Marquise, hung with Boucher’s glowing
pictures; the park with its parterres of rare flowers, its fine trees,
grottos, and fountains, its statues by Pigalle and Coustou, its varied
perspectives, its immense horizons,—all made of Bellevue a real
palace of Armida. At Versailles, the Marquise obtained from the King
a portion of the little park wherein to construct a gem of
architecture, which she called the Hermitage; it cloaked extreme
elegance under an appearance of simplicity. It had fine Persian
hangings, panelled wainscotings decorated by the most skilful
painters, thickets of myrtles, lilacs, and roses. This habitation is no
longer in existence; a part of its site is occupied by the rue de
l’Ermitage at Versailles. The Marquise had a house at Compiègne
and a lodge at Fontainebleau. At Paris she bought, for seven
hundred and thirty thousand livres, the hôtel d’Evreux, which is now
the Élysée.
At the Trianon her apartment was on the same floor with that of
Louis XV. At Clécy she received as if in a royal château. The King’s
visits to this splendid residence used to last three or four days, and
cost about one hundred thousand livres.
A woman so influential could not fail to have a swarm of
flatterers. The resources of fawning and hyperbole were exhausted
in her favor. The most exaggerated of her sycophants was Voltaire—
Voltaire to whom the republicans are nowadays raising statues. He
treated the Marquise as a superior being, a goddess, and pushed his
flattery to absurdity, to platitude. In 1745, the moment when the
reign of the favorite began, he sent her this compliment:—

“Sincère et tendre Pompadour


(Car je peux vous donner d’avance
Ce nom qui rime avec l’amour
Et qui sera bientôt le plus beau nom de France),
Ce tokai dont Votre Excellence
Dans Étioles me régala,
N’a-t-il pas quelque ressemblance
Avec le roi qui le donna?
Il est, comme lui, sans mélange;
Il unit, comme lui, la force à la douceur,
Plaît aux yeux, enchante le cœur,
Fait du bien et jamais ne change.”[38]
In 1746, when Marshal de Lowendal had just taken Berg-Op-
Zoom, it was Madame de Pompadour whom Voltaire felicitated on
the victory, in strains like these:—
“Les esprits, et les cœurs, et les remparts terribles,
Tout cède à ses efforts, tout fléchit sous sa loi,
Et Berg-Op-Zoom et vous, vous êtes invincibles;
Vous n’avez cédé qu’à mon roi.
Il vole dans vos bras du sein de la Victoire,
Le prix de ses travaux n’est que dans votre cœur.
Rien ne peut augmenter sa gloire,
Et vous augmentez son bonheur.”[39]

The Marquise rewarded Voltaire at the end of the same year by


producing the Enfant prodigue in the theatre of the little cabinets,
and taking the part of Lise herself. It was then that the poet, beside
himself with joy, addressed the beautiful actress the following lines,
which exasperated the daughters of Louis XV. and dissatisfied the
King himself:—
“Ainsi donc, vous réunissez
Tous les arts, tous les dons de plaire;
Pompadour, vous embellissez
La cour, le Parnasse et Cythère.
Charme de tous les yeux, trésor d’un seul mortel,
Que votre amour soit éternel!
Que tous vos jours soient marqués par des fêtes!
Que de nouveaux succès marquent ceux de Louis!
Vivez tous deux sans ennemis
Et gardez tous deux vos conquêtes!”[40]

So many madrigals were not enough. Both verse and prose were
needed. In addressing to the Marquise a copy of the Précis du siècle
de Louis XV. Voltaire inserted in it a passage, gravely congratulating
her upon that treaty of Aix-la-Chapelle which had so grievously
offended the national sentiment:—
“It must be owned that Europe may date its felicity from the day
of this peace. People will learn with surprise that it was the result of
the urgent counsels of a young lady of high rank, celebrated for her
charms, her singular talents, her wit, and an envied position. It was
the destiny of Europe in this long quarrel that a woman began it and
a woman ended it. The second has bestowed as many benefits as
the first caused harm.”
Can one be surprised, after this, that Madame de Pompadour
should have been persuaded of her own merit, wit, and even genius;
that she cherished strange illusions concerning her rôle and her
character; that she took herself seriously, even tragically; that she
regarded any adverse criticism of her as high treason against beauty
and majesty?
With such an array of luxury and power, such a mass of riches,
jewels, objects of art, such a court of ingenious and amiable
courtiers, with all that could soothe her vanity, coquetry, and pride,
with the ability to realize all her fancies and caprices, one might
perhaps think the favorite was happy. Well! no.
VI
THE GRIEFS OF THE MARQUISE DE POMPADOUR

“I
pity you much, Madame, while all the world envies you.” The
person who addressed this just remark to the Marquise de
Pompadour was her inseparable confidant, her lady’s maid, Madame
du Hausset, the woman to whom she told everything, whom she
always kept near her, and to whom she said: “The King and I rely on
you so fully that we pay no more attention to you than to a cat or
dog, but go right on talking.” The Marquise recognized the truth of
her confidant’s melancholy words: “Ah!” she answered, “my life is
like that of a Christian: a perpetual combat.” Strange comparison!
Most inexact comparison! for the Christian combats for God, while
the favorite was combating for the devil. This, in fact, was the cause
of her sadness. The love of God consoles one for all sacrifices; but
woe to the woman who makes herself the slave of a man! Madame
de Pompadour placed no confidence in Louis XV., and she was right.
The Maréchale de Mirepoix said to her one day: “It is your staircase
that the King likes; he is used to going up and down it. But if he
found another woman to whom he could talk about his hunting and
his affairs, it would be all the same to him at the end of three days.”
Listen to Madame du Hausset. She says in her Memoirs: “Madame
experienced many tribulations amidst all her grandeurs. Anonymous
letters were often written her containing threats to poison or
assassinate her; but what affected her most was the dread of being
supplanted by a rival. I never saw her in greater vexation than one
evening on her return from the salon of Marly. On entering, she
spitefully threw down her muff and mantle, and undressed with
extreme haste; then, sending away her other women, she said to
me after they went out: ‘I don’t believe anything can be more
insolent than that Madame de Coaslin. I had to play brelan at the
same table with her this evening, and you cannot imagine what I
suffered. The men and women seemed to take turns in coming to
examine us. Two or three times Madame de Coaslin said, looking at
me: “Va tout,” in the most insulting manner, and I thought I should
be ill when she said in a triumphant tone: “I have played kings!” I
wish you had seen her courtesy on quitting me!’” Thereupon
Madame du Hausset inquired what the master’s attitude had been.
“You don’t know him, my dear,” replied the Marquise; “if he were
going to put her in my apartment this evening he would treat her
coldly before people, and me with the greatest affection.” The
favorite was in constant alarm and anxiety. She believed in neither
the loyalty, the love, nor the friendship of the King. Thus, as has
been wittily said by M. Paul de Saint-Victor: “She spent her life in the
attitude of Scheherezade, sitting beside the bed where the caliph
slept, his sabre at hand. Like the head of the sultana, her favor
depended on a caprice of the master, on the gay or tiresome story
which she was about to tell him. And what happens in the thousand
and one nights of the harem from which she is excluded? Who
knows whether a firman scrawled by a grisette may not exile her to-
morrow to the depths of a province?” In spite of her knowledge of
frivolous trifles and her array of seductions, the Marquise could not
succeed in diverting Louis XV. It is again Madame du Hausset who
tells us as much: “The King was habitually very dismal and liked
everything which recalled the thought of death, even though he
feared it very much.” This melancholy humor of the monarch
distressed his mistress. “What a singular pleasure,” said she, “to
occupy one’s self with things the very notion of which ought to be
banished, especially when one leads such a happy life!” Madame de
Pompadour did not reflect when she talked like this. She forgot that
a debauchee can never be happy long. The sovereign and his
favorite were both suffering from the same malady; their
consciences were not at rest. To both of them might be applied the
verses addressed by Lucretius to the Epicurean youth of Rome,
which we translate as follows: “They inhale sweet perfumes; they
deck themselves with wreaths and garlands; but from the middle of
the fount of pleasures rises bitterness, and sharp thorns pierce
through the flowers; remorse rebukes them from the depths of their
soul and reproaches them with days lost in idleness.”
Of what use then were luxury and splendor to her? The Marquise
was greeted by adulations in all her châteaux, all her houses.
Nowhere did she find esteem. To tell the truth, all this array of
factitious grandeur, all this pretence at decorum, was but a parody.
Do what she might, the mistress of Louis XV. was in reality nothing
but the first kept woman in the kingdom. Loaded and overwhelmed
with proofs of royal munificence, she never called herself satisfied;
ambition, like sensual pleasure, is insatiable. The love of money and
the love of flattery never say: “It is enough!”
The sumptuous abodes the favorite found means to acquire were,
after all, but monuments of her shame. Her house at Paris (now the
Élysée) was styled the palace of the queen of courtesans, ædes
reginæ meretricum. When the equestrian statue of Louis XV., with its
four allegorical figures sculptured by Pigalle, was set up in the Place
Louis XV., the crowd pointing out to each other these emblems of
Force, Prudence, Justice, Love of Peace, said they were the four
most famous mistresses of the monarch: Mesdames de Mailly, de
Vintimille, de Châteauroux, and de Pompadour, and a paper
containing these verses was posted on the statue itself:—
“Grotesque monument, infâme piédestal;
Les Vertus sont à pied, et le vice à cheval.”[41]

The honors heaped on her family by the all-powerful Marquise


were not taken seriously. When her mother, Farmer-General
Lenormand de Tournehem’s mistress, died, this quatrain was
circulated:—

“Ci-gît qui, sortant d’un fumier,


Pour faire sa fortune entière,
Vendit son honneur au fermier
Et sa fille au propriétaire.”[42]

When her brother, Abel Poisson, metamorphosed into Marquis de


Marigny and superintendent of the crown buildings, had received the
blue ribbon of the Holy Spirit, people said the fish was turning blue.
In 1754 Madame de Pompadour had the misfortune of losing her
only daughter, Alexandrine d’Étioles, who was only eleven years old.
She would have liked to marry her to young De Vintimille, who
passed as the son of Louis XV. One day she brought the two children
together, as if accidentally, at Bellevue, and showing them to the
King, said to him: “That would be a fine couple.” Louis XV. received
this overture more than coldly. Madame de Pompadour said
afterwards to Madame du Hausset: “If he were a Louis XIV., he
would make a Duke du Maine of the child, but I do not ask so much
as that; a position and a ducal title is very little for his son, and it is
because he is his son that I prefer him, my dear, to all the little
dukes of the court. My grandchildren would share a resemblance to
both grandfather and grandmother, and this blending which I expect
to see will one day be my happiness.”—“Tears came to her eyes in
saying these words,” adds Madame du Hausset.
Sainte-Beuve has poured witty contempt on this adulterous
dream. “It seems to me,” says the prince of critics, “that one lights
unexpectedly on the perverted but persistent bourgeois vein in this
wish of Madame de Pompadour; she brings ideas of affection and
family arrangements even into her adulterous combinations. She has
sentiments; she thinks of herself already as a most affectionate
grandmother. A picture, which I would call a Greuze-Pompadour,
might be made of this scene, the Marquise tearfully pointing out the
two children to the King.”
The favorite found it hard to renounce her cherished project of
this alliance. Afterwards she thought of the young Duke de Fronsac,
Richelieu’s son, as a husband for her daughter. She caused overtures
to be made to the celebrated courtier. He answered by a disguised
refusal. “My son,” said he, “has the honor of belonging, on his
mother’s side, to the house of Lorraine; hence I cannot dispose of
him without the consent of that family, but I shall proceed to
demand it urgently if the Marquise still persists in her intentions.”
Madame de Pompadour understood, and insisted no further. She
planned another marriage for her daughter, who was promised to
the young Duke de Pecquigny, son of the Duke de Chaulnes of the
De Luynes family. But Mademoiselle d’Étioles died prematurely at the
very time when the marriage was about to be contracted. She was
buried in the sepulchre her mother had bought from an illustrious
family. “The bones of the La Trémoille,” said the Princess de
Talmond, “must have been must astonished at finding fish bones (les
arêtes des Poisson) near them.”
We have seen the disgusting flatteries of which the Marquise was
the object. These hyperboles of interested praise had a terrible
counterpart. While the court was obsequious, Paris remained
implacable. There was an incessant succession of sneers, satires,
and invectives. There had been mazarinades of old; now there were
poissonades. Minister Maurepas was the instigator and often the
author of these violent rhymed diatribes, which made people say
France was an absolute monarchy tempered by ballads. The masses
avenged themselves by refrains of more than Gallic animation. We
cite one among a thousand. It was sung to the air Trembleurs d’Isis:

“Les grands seigneurs s’avilissent,
Les financiers s’enrichissent,
Et les Poissons s’agrandissent;
C’est le règne des vauriens.
On épuise la finance,
En bâtiments, on dépense,
L’État tombe en décadence,
Le roi ne met ordre à rien.
“Une petite bourgeoise,
Élevée à la grivoise,
Mesurant tout à sa toise,
Fait de la cour un taudis;
Louis, malgré son scrupule,
Froidement pour elle brûle,
Et son amour ridicule
A fait rire tout Paris....
“La contenance éventée,
Et chaque dent tachetée,
La peau jaune et truitée,
Les yeux froids et le cou long,
Sans esprit, sans caractère,
L’âme vile et mercenaire,
Les propos d’une commère,
Tout est bas chez la Poisson.
“Si dans les beautés choisies
Elle était des plus jolies,
On pardonne des folies,
Quand l’objet est un bijou.
Mais pour sotte créature
Et pour si plate figure
Exciter tant de murmure,
Chacun juge le roi fou.”[43]

Nor did people content themselves with ballads. They likewise


produced long pieces of emphatic verse, distilling venom and hatred.
More or less skilful imitators of Juvenal composed satires full of gall
and bitterness. What specially excited the indignation of the authors
of these diatribes were the representations at the theatre of the little
cabinets. One of them, addressing himself to Madame de
Pompadour, exclaimed:—
“Parmi ces histrions qui règnent avec toi,
Qui pourra désormais reconnaître son roi?”[44]

Another thus expressed himself:—


“Sur le trône français on fait regner l’amour.
La fureur du théâtre assassine la cour.
Les palais de nos rois jadis si respectables,
Perdent tout leur éclat, deviennent méprisables;
Ils ne sont habités que par des baladins!...”[45]

A pamphlet entitled “The School of Man, or parallel between


contemporary portraits and those of Holy Writ,” contained attacks of
this sort against Louis XV.: “Too much incommoded by his greatness
to take a girl from the green room, Lindor satisfied himself in true
princely style: he had a large house with a theatre in it built
expressly for him, where his mistress became a danseuse by title
and office; men infatuated by the vanity of dancing women,
insensate imitators of Candaules, do not fancy that the last Gyges
died in Lydia.”
One should read the Memoirs of the Marquis d’Argenson and
those of Barbier the advocate in order to get a just notion of the
hatred felt for the Marquise by both the aristocracy and the middle
classes. The people despised her quite as much, and held her solely
responsible for all wretchedness and every disaster. The luxury of
this parvenu irritated them, and they detested her profoundly. The
following quatrain expressed the popular sentiment:—
“Fille d’une sangsue et sangsue elle-même,
Poisson d’une arrogance extrême,
Étale en ce château, sans crainte et sans effroi,
La substance du peuple et la honte du roi.”[46]

For those who knew how to listen, the Revolutionary storm was
already rumbling in the distance.
Madame de Pompadour could not rely on her flatterers
themselves. Voltaire, who had burned so much incense at the
adored feet of the Marquise, who at Versailles had been her most
zealous, ardent, enthusiastic courtier, forgot all that in his retreat at
Ferney. He chaffed at his former idol and drew a most malicious
portrait of her in his poem La Pucelle.
Thoroughly acquainted with the tone of public opinion, since she
had her own police and an arrangement with the director of the
post-office, who violated the secret of letters for her, Madame de
Pompadour was in despair at so many attacks. Uneasy, feverish,
dissatisfied with the King and the kingdom, considering herself as a
victim of destiny, a woman unjustly dealt with by fortune, spitefully
angry at Frederick the Great, who scoffed at her; at Louis XV., who
neglected her for the young girls of the Deer Park; at the clergy, who
regarded her as a tool of hell; at the Parliaments, which disdained
her; at the nobility, who saw nothing in her but an ambitious
bourgeoise; at the middle classes, who reproached her for being
immoral; at all France, which scorned her,—she suffered as much in
her vanity as in her pride, and said to her confidant, Madame du
Hausset: “The sorceress told me I should have time to repent before
dying; I believe it, for I shall die of nothing but chagrin.”
VII
MADAME DE POMPADOUR, LADY OF THE QUEEN’S PALACE

M
adame de Pompadour was ready to play all parts in order to
preserve her empire. To be an actress and a political woman
was not enough; she willingly consented to become by turns, and
simultaneously if need were, a devotee and a procuress, to favorize
now the Church and now the Deer Park, to submit to every
transformation, every servitude: Omnia serviliter pro dominatione.
Never did any minister cling more firmly to his portfolio, never had
any ambitious man a greater thirst for power.
Louis XV. had a substratum of religion which made the favorite
uneasy. The day he insisted on her reading one of Bourdaloue’s
sermons she was frightened. With all her audacity she never dared
to criticise the Church in the presence of the Most Christian King; for
irregular as his own conduct was, he would not suffer the faith of his
fathers to be insulted in his hearing. To keep her place, the Marquise
would have asked nothing better than to assume the austere
demeanor of a Madame de Maintenon; but she was married,
unfortunately, and so was the King, and Catholicism has never
compromised with concubinage or adultery. Hence Madame de
Pompadour sought to avert the difficulty. She put on a half-way
devotion which was wholly worldly, made for show, a sort of
compromise between God and the devil, between the Church and
the boudoir, the oratory and the alcove, a spurious, derisory,
hypocritical devotion, examples of which are given by many women
of our own century as well as of the last.
She had determined to make a figure in the Versailles chapel from
the time her favor began. She meant to shine everywhere, even
before the altars. It was this that made her request the Queen’s
authorization to carry one of the basins at the ceremony of feet
washing on Maundy Thursday, and collect the offerings at the High
Mass on Easter Sunday. But easy as she was where no one but
herself was concerned, Marie Leczinska became severe where God
was in question: she refused.
The Jubilee of 1751 redoubled the anxieties of the Marquise.
D’Argenson wrote, February 2: “People assert that the King will gain
his Jubilee and make his Easter Communion. The Marquise says
there is no longer anything but friendship between the King and her,
and that they will put a fortnight’s retreat and truce even to this
friendship.” The attitude of a repentant Magdalen would not have
suited a woman like Madame de Pompadour. She was willing enough
for a little devotion, but of an elegant and worldly sort, ostentatious
and luxurious. The theatre, in a word, pleased her much better than
the church. D’Argenson wrote again, February 6: “All Paris has been
talking of the representation of Thétis et Pélée, eight days ago, at
which the Marquise de Pompadour was present. The actors
addressed her directly in the gallant parts, such as, ‘Reign, beautiful
Thetis!’ This she received with a triumphant air which a woman of
different extraction would not have assumed; for some feed their
vanity on what others could not endure without shame.” But what
afflicted the haughty favorite was the thought that all this success
might topple over in an instant, like a house of cards. At the very
time when, always an actress, even under the deceptive
appearances of her so-called repentance, she was having a statue of
herself as the goddess of Friendship made for Bellevue, she had
several attacks of fever—people called it the Jubilee fever.
Madame de Mailly, the woman with whom Louis XV. had begun
his scandalous life, was at this time at her last extremity. One reads
in the Memoirs of the Marquis d’Argenson, under date of March 27,
1751: “Madame de Mailly, former mistress of the King, is dying. It
was thought she was better, but the inflammation of the lungs is
increasing, and she has a hopeless fever. The King has not even
once sent openly to make inquiries, but the Marquis de Gontaud has
bulletins four times a day and transmits them to the King, who is
afraid of offending Madame de Pompadour. I am convinced he will
be much affected by her death. The pious people, those who believe
in Providence, remark that, the King having had the three sisters,
they have all died young. This one, who was the first, and not
incestuous, is dying piously and the death of the just: it is even
through her religious practices that she contracted her malady;
apparently she will have a holy death. The other two died in horrible
anguish, and much younger. People reflect also that God is so
desirous of the King’s conversion, that this death happens just in the
Jubilee time, so as to touch His Majesty, already prepared by
sermons and disposed to make his Jubilee sincerely. However, in the
cabinets, divertisements and ballets are still going on secretly.”
In Barbier’s journal are encountered similar reflections on the
terrors of the Marquise: “Everybody,” he writes, “is carefully
watching for what will happen at the Jubilee. They say Madame de
Pompadour dreads the results of it. There are many at the court, not
merely ecclesiastics, but men and women who are expecting this
event to ruin the Marquise, whose abuse of her position has for
some time gained her the hatred of all the nobles. The King can
hardly remain at Versailles without making his Jubilee. Public
prejudice is carried to the point of respecting the Jubilee more than
the Easter duties which are of obligation. If he makes his Jubilee, he
cannot well return to the château of Bellevue a fortnight later, and a
month’s absence would be dangerous. There are lovers of the court
who are now forming a plan to find a new mistress for the King after
the Jubilee; for, melancholy as it may be, he must have some
diversion; and if he should altogether fear the devil and decide on
amendment, this would be not at all amusing for the nobles. This
event, then, which is not far distant, is what is agitating the public
high and low.”
Madame de Mailly breathed her last March 30. In her will she had
asked to be buried in the cemetery, among the poor, and to have a
wooden cross. The Marquis d’Argenson writes: “These austerities,
penances, and poverty increase the adverse opinion against her who
now occupies her former place and whose conduct is so very
different. It is also remarked, for the honor of religion, that Madame
de Mailly, who was often subject to fits of ill temper, which was the
cause of her being banished by the King, had become as mild and
equable as possible. People say that if she was not holy, no other
woman ever will be.”
But Madame de Pompadour was once more victorious. The King
did not allow himself to be touched by the death of his former
mistress, and, spite of the warnings of heaven, he did not make his
Jubilee. Still the Marquise was not tranquil. D’Argenson wrote,
December 11, 1752: “Madame de Pompadour has been spitting
blood since her youth. Et in peccato concepit eam mater sua. She is
becoming as dry as a stick, and one can see her growing thin with
jealousy.” And September 17, 1753: “The King is becoming
superstitiously devout, respecting the clergy more than morals.
Marshal de Richelieu said to me in a jesting way: ‘The King shows
angelic devotion. He won’t do anything without the episcopate in the
affairs of Languedoc.’”
Madame de Pompadour no longer appealed to the senses of Louis
XV. Sensuality failing her, she would have liked to be able to press
religion into her service. She sought to create a new rôle for herself
as favorite, more minister than mistress; to legitimate by duration as
well as by a certain decorum her liaison with the King; to assume, in
brief, an attitude as friend, counsellor, I might almost say matron.
Negotiating her conversion with the Jesuits as if it were a
diplomatic affair, she demanded as a condition sine quâ non, that
she should remain at Versailles. But here was the difficult point. The
clergy, even at a period of abasement, retained their principles, and
the Church would not be the dupe of a woman. But one thing, the
absolution of a priest, was needful to enable her to go on playing
her part as companion to the King, female minister, peacemaker
between the King and the royal family, the Crown and the
Parliaments, the clergy and the philosophers. All she had to do to
merit and obtain this absolution was to withdraw from the court. But
the Marquise would have preferred death to retreat. The atmosphere
of Versailles was indispensable to her. Far from the scene of her
sorry triumphs she would have expired in rage and despair. Louis XV.
well knew that to dismiss her would be to kill her. Therefore he kept
her near him, but solely through compassion.
Madame de Pompadour had put herself in communication with a
Jesuit, Père de Sacy, whom she had formerly known, and from
whom she hoped to gain, not only absolution, but permission to
remain at the palace of Versailles. As, in the preceding reign, the
“mistress thundering and triumphant,” Madame de Montespan, had
been seen to humble herself before a simple curé, the all-powerful
Marquise de Pompadour was now seen humbly soliciting a Jesuit.
Père de Sacy remained firm: he would not let himself be moved by
the fine protestations of the Marquise. It was in vain to show him
that the communications between the apartments of the King and
the favorite were now walled up; useless for the partisans of loose
morality and worldly religion to say to him that he must not
discourage repentance; that too much severity would spoil all; that
the Church had need of Madame de Pompadour against the
Encyclopedists; in a word, that there ought to be such a thing as
compromising with heaven. The Jesuit rejected this theory of
relaxation and culpable condescension. He reminded his pretended
penitent that she had a husband still living,—a husband of whom
she could not complain, and that her place was not at the palace of
Versailles, but at the side of M. Lenormand d’Étioles. This annoying
souvenir exasperated the favorite, infuriated by the conjugal
phantom that rose before her, and thwarted all her plans. When she
was convinced that, in spite of her feminine tricks, she could never
bend Père de Sacy, she dismissed him;[47] and undoubtedly the
admirable conduct of the Jesuits was one of the causes which
brought about the expulsion of the order a few years later. Madame
de Pompadour was vindictive. She never pardoned any one who had
the audacity to displease her.
Could one believe it? The favorite pushed her assurance to the
point of posing as a victim. To credit her, people were unjustly
opposing obstacles to her conversion and that of the King. Priests
who refused absolution in this way were enemies of the throne and
the altar. At the same time, she shamelessly solicited a place as lady
of the Queen’s palace. Marie Leczinska’s obligingness had already
been carried too far. This time the good Queen made some
observations. To receive to a place of honor a woman separated
from her husband, a person who could not even claim to receive the
benefits of the general communion, was an ignominy to which Louis
XV. could not really wish to condemn a Queen of France.
Accomplished intriguer as she was, Madame de Pompadour was not
yet discouraged. She declared her willingness to be reconciled with
her husband, at the same time secretly acquainting M. Lenormand
d’Étioles that he would do well to refrain from accepting such an
offer. The letter she wrote him was replete with the finest
sentiments. As much as she had scandalized society by her
separation, so much she promised to edify it hereafter by an
irreproachable union with her husband. But this promise was only a
feint. Moreover, M. d’Étioles was hardly anxious to take back his
wife. He might have applied to her the idea expressed in this line of
a modern tragedy:—
Et mon indifférence a tué mon mépris.
And my indifference has slain my scorn.

It was long since the woman who had ceased to bear his name
and whose desertion had once rendered him so unhappy, had
excited in him either anger or resentment. He had wept for Madame
d’Étioles. But Madame d’Étioles had been dead more than ten years,
and he did not know Madame the Marquise de Pompadour. Nor had
he any desire to know her. What he was told about her in nowise
tempted him. He greatly preferred a former dancer at the opera,
Mademoiselle Rem, with whom he lived maritally, and for whose
sake he had refused the embassy from France to Constantinople.
Madame de Pompadour triumphed. The really guilty person, said
she, was her husband. He and he alone committed the sin, he who
refused to open his arms to a repentant spouse. She could not re-
enter the conjugal abode by force. Hence the Queen could have no
complaint against her, and no opposition could be made against her
obtaining, after having received absolution, that place as lady of the
palace, which was the height of her desires. She formally received
her Easter communion at the church of Saint Louis, Versailles. But it
was not Père de Sacy who heard her confession, but another priest.
“I had been surprised,” writes Madame du Hausset, “for some
time past to see the Duchess de Luynes coming secretly to Madame.
Afterwards she came openly; and one evening, Madame having
gone to bed, called me and said: ‘My dear, you are going to be very
well contented, the Queen is giving me a place as lady of the palace;
to-morrow I am to be presented; you must make me look very
handsome.’ I knew that the King was not quite so much at his ease
about it; he was afraid of scandal and that people might think he
had forced the Queen to make this nomination. But there was
nothing of that sort. It was represented to the Princess that it would
be an heroic act on her part to forget the past; that all scandal
would be obliterated when it was seen that an honorable position
was what retained Madame at court, and that this would be the best
proof that nothing but friendship existed any longer between the
King and his favorite. The Queen received her very well. The pious
sort flattered themselves that they would be protected by Madame,
and for some time sang her praises.... This was the time when
Madame appeared to me the most contented. The devotees made
no scruples about visiting her and did not forget themselves when
opportunity offered.... The doctor (Quesnay) laughed at this change
of scenes and made merry at the expense of the devotees. ‘And yet,’
I said to him, ‘they are consistent and may be in good faith.’ ‘Yes,’
said he, ‘but they ought not to ask for anything.’”
The Marquise de Pompadour, who had had the tabouret and the
honors of a duchess since 1752, received her brevet as lady of the
Queen’s palace February 7, 1756. She began the next day her week
of attendance on Marie Leczinska, at the state dinner in a superb
costume.
D’Argenson, whose morality is often peculiar, finds the thing
natural enough. He approves rather than criticises. “Sunday
evening,” he writes, “the Marquise de Pompadour was declared at
Versailles lady of the Queen’s palace, whence it is conjectured that
she is no longer the King’s mistress. It is even said that she begins
to talk devotion and Molinism, and is going to try and please the
Queen as much as she has the King. All this confidence which has
been evident during the three years since the King began to have
new mistresses is merely the reward of the sweetness and humility
with which she has accepted her lover’s infidelities. This is only
precarious and mere pretence, or, rather, it comes from a sentiment
of friendship, good taste, and gratitude, and a good-nature in which
love counts for nothing. But these reasonable sentiments can
accomplish much in a sensible and well-ordered heart like that of the
King.” Here one gets the sum of the morality of the eighteenth
century. What could be expected of a society in which even worthy
men could use such language and show such complaisance?
VIII
MADAME DE POMPADOUR AND THE ATTEMPT OF DAMIENS

M
adame de Pompadour was destined to “live in the midst of
alarms.” For nearly a year she had been congratulating herself
on the cleverness with which she had carried by assault the post of
lady of the Queen’s palace, and had dismissed the confessors, of
whom she thought she had no more need, when an unforeseen
event was very near making her lose all the ground she had so
painfully acquired.
Toward six o’clock in the evening of January 5, 1757, Louis XV.
had just come down the little staircase leading from his apartments
to a vestibule facing the marble court, and was about to enter a
carriage, when he was struck by a penknife in the hand of a person
named Damiens, who, either through folly or fanaticism, wished not
to kill him, but to give him a warning. The King thought himself
mortally wounded. He belonged to that category of Christians who
are never pious but when they are sick. When in good health they
say: “There is always time to repent.” But if danger threatens them,
they tremble, they go to confession, they become saints for the time
being, reserving the privilege of resuming their vicious habits as
soon as their health returns. When he thought death was facing him,
Louis XV. expressed himself in terms worthy of the Most Christian
King. At Metz he had been sublime. He was not less eloquent at
Versailles. The noblest maxims were on his lips, the most beautiful
sentiments in his heart. He named his son lieutenant-general of the
kingdom, and said to him with emotion: “I leave you a very
disturbed realm; I hope that you may govern it better than I have
done.” He melted into tears of edification and admiration all those
who came near him. This was no longer the man of the Deer Park; it
was the son of Saint Louis.
One of his first words after being struck was a cry for a priest. His
Jesuit confessor, Père Desmarets, was not just then at Versailles. A

You might also like