100% found this document useful (3 votes)
108 views

Thinking with Types Type level Programming in Haskell Sandy Maguire all chapter instant download

Types

Uploaded by

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

Thinking with Types Type level Programming in Haskell Sandy Maguire all chapter instant download

Types

Uploaded by

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

Experience Seamless Full Ebook Downloads for Every Genre at textbookfull.

com

Thinking with Types Type level Programming in


Haskell Sandy Maguire

https://textbookfull.com/product/thinking-with-types-type-
level-programming-in-haskell-sandy-maguire/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://textbookfull.com


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

Thinking Functionally With Haskell Richard Bird

https://textbookfull.com/product/thinking-functionally-with-haskell-
richard-bird/

textboxfull.com

Programming in Haskell 2nd Edition Graham Hutton

https://textbookfull.com/product/programming-in-haskell-2nd-edition-
graham-hutton/

textboxfull.com

Programming in Haskell Second Edition, 5Th Printing


Edition Hutton

https://textbookfull.com/product/programming-in-haskell-second-
edition-5th-printing-edition-hutton/

textboxfull.com

Algebra Driven Design Elegant Software from Simple


Building Blocks Version 1 1 2 Sandy Maguire

https://textbookfull.com/product/algebra-driven-design-elegant-
software-from-simple-building-blocks-version-1-1-2-sandy-maguire/

textboxfull.com
Thinking Low Level Writing High Level 2nd Edition Randall
Hyde

https://textbookfull.com/product/thinking-low-level-writing-high-
level-2nd-edition-randall-hyde/

textboxfull.com

Haskell The Ultimate Beginner s Guide to Learn Haskell


Programming Step by Step 1st Edition Claudia Alves

https://textbookfull.com/product/haskell-the-ultimate-beginner-s-
guide-to-learn-haskell-programming-step-by-step-1st-edition-claudia-
alves/
textboxfull.com

The Haskell Road to Logic Maths and Programming Kees Doets

https://textbookfull.com/product/the-haskell-road-to-logic-maths-and-
programming-kees-doets/

textboxfull.com

Algorithm Design with Haskell Richard S. Bird

https://textbookfull.com/product/algorithm-design-with-haskell-
richard-s-bird/

textboxfull.com

Thinking with Type: A Critical Guide for Designers,


Writers, Editors, and Students (3rd Edition, Revised and
Expanded) Ellen Lupton
https://textbookfull.com/product/thinking-with-type-a-critical-guide-
for-designers-writers-editors-and-students-3rd-edition-revised-and-
expanded-ellen-lupton/
textboxfull.com
Thin
Thinki
king
ng wi
with
th Ty
Type
pess

Sandy
Sandy Maguire
Maguire
Copy
Copyrig
right
ht ©201
©2018,
8, Sand
Sandyy Magu
Maguire
ire

All rights reserved.

First
First Edition
Edition
When people say
“but most business logic bugs
aren’t type errors,”
I just want to show them
how to make bugs
into type errors.
MATT PARSONS
Contents

Preface ix
Acknowledgments xi
Introduction 1

I Fundamentals 5
1 The Algebra Behind Types 7
1.1 Isomorphisms and Cardinalities . . . . . . . . . . . . . . . 7
1.2 Sum, Product and Exponential Types . . . . . . . . . . . . 10
1.3 Example: Tic-Tac-Toe . . . . . . . . . . . . . . . . . . . . . 13
1.4 The Curry–Howard Isomorphism . . . . . . . . . . . . . . 15
1.5 Canonical Representations . . . . . . . . . . . . . . . . . . 16
2 Terms, Types and Kinds 19
2.1 The Kind System . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.1.1 The Kind of “Types” . . . . . . . . . . . . . . . . . . 20
2.1.2 Arrow Kinds . . . . . . . . . . . . . . . . . . . . . . . 20
2.1.3 Constraint Kinds . . . . . . . . . . . . . . . . . . . . 21
2.2 Data Kinds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.3 Promotion of Built-In Types . . . . . . . . . . . . . . . . . 25
2.3.1 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.3.2 Natural Numbers . . . . . . . . . . . . . . . . . . . . 27
2.3.3 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.3.4 Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.4 Type-Level Functions . . . . . . . . . . . . . . . . . . . . . 30
3 Variance 35

v
vi CONTENTS

II Lifting Restrictions 41
4 Working with Types 43
4.1 Type Scoping . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.2 Type Applications . . . . . . . . . . . . . . . . . . . . . . . . 45
4.3 Ambiguous Types and Non-Injectivity . . . . . . . . . . . 47
5 Constraints and GADTs 51
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.2 GADTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
5.3 Heterogeneous Lists . . . . . . . . . . . . . . . . . . . . . . 55
6 Rank-N Types 61
6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
6.2 Ranks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.3 The Nitty Gritty Details . . . . . . . . . . . . . . . . . . . . . 65
6.4 The Continuation Monad . . . . . . . . . . . . . . . . . . . 66
7 Existential Types 71
7.1 Existential Types and Eliminators . . . . . . . . . . . . . . 71
7.1.1 Dynamic Types . . . . . . . . . . . . . . . . . . . . . 74
7.1.2 Generalized Constraint Kinded Existentials . . . . 76
7.2 Scoping Information with Existentials . . . . . . . . . . . 79
8 Roles 85
8.1 Coercions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8.2 Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

III Computing at the Type-Level 95


9 Associated Type Families 97
9.1 Building Types from a Schema . . . . . . . . . . . . . . . . 98
9.2 Generating Associated Terms . . . . . . . . . . . . . . . . . 102
10 First Class Families 107
10.1 Defunctionalization . . . . . . . . . . . . . . . . . . . . . . . 107
10.2 Type-Level Defunctionalization . . . . . . . . . . . . . . . 109
10.3 Working with First Class Families . . . . . . . . . . . . . . 113
10.4 Ad-Hoc Polymorphism . . . . . . . . . . . . . . . . . . . . . 116
CONTENTS vii

11 Extensible Data 119


11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
11.2 Open Sums . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
11.3 Open Products . . . . . . . . . . . . . . . . . . . . . . . . . . 125
11.4 Overloaded Labels . . . . . . . . . . . . . . . . . . . . . . . . 131
12 Custom Type Errors 133
13 Generics 141
13.1 Generic Representations . . . . . . . . . . . . . . . . . . . . 142
13.2 Deriving Structural Polymorphism . . . . . . . . . . . . . 145
13.3 Using Generic Metadata . . . . . . . . . . . . . . . . . . . . 151
13.4 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
13.5 Kan Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . 165
14 Indexed Monads 169
14.1 Definition and Necessary Machinery . . . . . . . . . . . . 169
14.2 Linear Allocations . . . . . . . . . . . . . . . . . . . . . . . . 173
15 Dependent Types 181
15.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
15.2 Ad-Hoc Implementation . . . . . . . . . . . . . . . . . . . . 182
15.3 Generalized Machinery . . . . . . . . . . . . . . . . . . . . . 187
15.4 The Singletons Package . . . . . . . . . . . . . . . . . . . . 192
15.5 Dependent Pairs . . . . . . . . . . . . . . . . . . . . . . . . . 195
15.5.1 Structured Logging . . . . . . . . . . . . . . . . . . . 199

IV Appendices 203
Glossary 205
Solutions 211
Bibliography 233
About the Author 235
viii CONTENTS
Preface
Thinking with Types started, as so many of my projects do,
accidentally. I was unemployed, bored, and starting to get tired of
answering the same questions over and over again in Haskell
chat-rooms. And so I started a quick document, jotting down a
bunch of type-level programming topics I thought it’d be fun to
write blog posts about.
This document rather quickly turned into an outline of what those
blog posts might look like, but as I was about to tease it apart into
separate files I stopped myself. Why not turn it into a book instead?
I approached some friends to see if anyone was interested in
writing it with me. A few nibbles, but nobody had time they wanted
to dedicate to such a thing. My excitement subsequently burned out,
and the idea lay dormant on the back-burner for a few months.
But I was still unemployed, and I was still bored, and I found
myself slowly fleshing out chapters regardless. My enthusiasm for
writing a book had died down, but I still felt the urge to write. A
friend caught me writing one day, and dared me to publish what I
had. I acquiesced.
And so on July 8th, 2018, I posted a 37 page document to reddit,
gauging if there was any interest from the community in such a book.
To my continual surprise, there was. The response was about 100x
bigger than I was expecting. Kind words and letters of support rolled
in, many of whom promised to pay me in order to continue writing
it.
That was enough for me. I put together a Patreon, started selling
early access to the book, and was o to the races. The promise was
to publish weekly updates, which—combined with not wanting to
commit fraud—kept me extremely motivated to get this book
finished. It’s a powerful technique to stay focused, and I’d strongly

ix
x CONTENTS

recommend it to anyone who is better at starting projects than


finishing them.
It sounds cliche, but this book couldn’t have happened without
the overwhelming support of the Haskell community. It’s
particularly telling that every day I learn new things from them
about this marvelous language, even after five years.
Written with love by Sandy Maguire. 2018.
Acknowledgments

This book couldn’t have happened without the support of many,


many fantastic people. I’d like to thank everyone for their support,
their patronage and their enthusiasm. Some of the exceptionally
instrumental people, however, require further accolades. In
particular:
Fintan Halpenny, for his everlasting gusto. My unocial editor,
publicist, and second pair of eyes. The only person I know who’s
actually done all of the exercises.
Irene Papakonstantinou, for her untiring support, who first
encouraged me to publish this book, who bullied me into staying on
schedule, and for putting her money where her mouth was.
Jessie Natasha, for patiently answering my non-stop design
questions. For time and time again oering me her sense of style,
and spending long hours with me helping make the book look as
good as it does.
Anushervon Saidmuradov, whose support for me greatly exceeds
his interest in Haskell.
Furthermore, this book wouldn’t have been possible without the
financial support of Habito, Mirzhan Irkegulov, Michael Koloberdin,
and Chris Double.

xi
xii CONTENTS
Introduction
Type-level programming is an uncommon calling. While most
programmers are concerned with getting more of their code to
compile, we type-level programmers are trying our best to prevent
code from compiling.
Strictly speaking, the job of types is twinfold—they prevent
(wrong) things from compiling, and in doing so, they help guide us
towards more elegant solutions. For example, if there are ten
solutions to a problem, and nine of them be poorly-typed, then we
need not look very hard for the right answer.
But make no mistake—this book is primarily about reducing the
circumstances under which a program compiles. If you’re a beginner
Haskell programmer who feels like GHC argues with you too often,
who often finds type errors inscrutable, then this book is probably
not for you. Not yet.
So whom is this book for? The target audience I’ve been trying to
write for are intermediate-to-proficient with the language. They’re
capable of solving real problems in Haskell, and doing it without too
much hassle. They need not have strong opinions on ExceptT vs
throwing exceptions in IO , nor do they need to know how to inspect
generated Core to find performance bottlenecks.
But the target reader should have a healthy sense of unease
about the programs they write. They should look at their comments
saying “don’t call this function with n = 5 because it will crash,”
and wonder if there’s some way to teach the compiler about that.
The reader should nervously eyeball their calls to error that they’re
convinced can’t possibly happen, but are required to make the
type-checker happy.
In short, the reader should be looking for opportunities to make
less code compile. This is not out of a sense of masochism, anarchy,

1
2 CONTENTS

or any such thing. Rather, this desire comes from a place of


benevolence—a little frustration with the type-checker now is
preferable to a hard-to-find bug making its way into production.
Type-level programming, like anything, is best in moderation. It
comes with its own costs in terms of complexity, and as such should
be wielded with care. While it’s pretty crucial that your financial
application handling billions of dollars a day runs smoothly, it’s a
little less critical if your hobbyist video game draws a single frame of
gameplay incorrectly. In the first case, it’s probably worthwhile to
use whatever tools you have in order to prevent things from going
wrong. In the second, these techniques are likely too heavy-handed.
Style is a notoriously dicult thing to teach—in a very real sense,
style seems to be what’sleft after we’ve extracted from a subject all of
the things we know how to teach. Unfortunately, when to use type-
level programming is largely a matter of style. It’s easy to take the
ball and run with it, but discretion is divine.
When in doubt, err on the side of not doing it at the type-level.
Save these techniques for the cases where it’d be catastrophic to get
things wrong, for the cases where a little type-level stu goes a long
way, and for the cases where it will drastically improve the API. If
your use-case isn’t obviously one of these, it’s a good bet that there
is a cleaner and easier means of doing it with values.
But let’s talk more about types themselves.
As a group, I think it’s fair to say that Haskellers are contrarians.
Mostofus,I’dsuspect,havespentatleastoneeveningtryingtoextol
the virtues of a strong type system to a dynamically typed colleague.
They’ll say things along the lines of “I like Ruby because the types
don’t get in my way.” Though our first instinct, as proponents of
strongly typed systems, might be to forcibly connect our head to the
table, I think this is a criticism worth keeping in mind.
As Haskellers, we certainly have strong opinions about the value
of types. They are useful, and they do carry their weight in gold
when coding, debugging and refactoring. While we can dismiss our
colleague’s complaints with a wave of the hand and the justification
that they’ve never seen a “real” type system before, we are doing
them and ourselves a disservice both. Such a flippant response is to
ignore the spirit of their unhappiness—types often do get in the way.
We’ve just learned to blind ourselves to these shortcomings, rather
than to bite the bullet and entertain that maybe types aren’t always
CONTENTS 3

the solution to every problem.


Simon Peyton-Jones, one of the primary authors of Haskell, is
quick to acknowledge the fact that there are plenty of error-free
programs ruled out by a type system. Consider, for example, the
following program which has a type-error, but never actually
evaluates it:
fst ("no problems", True <> 17)

Because the type error gets ignored lazily by fst, evaluation of


such an expression will happily produce "no problems" at runtime.
Despite the fact that we consider it to be ill-typed, it is in fact,
well-behaved. The usefulness of such an example is admittedly low,
but the point stands; types often do get in the way of perfectly
reasonable programs.
Sometimes such an obstruction comes under the guise of “it’s not
clear what type this thing should have.” One particularly poignant
case of this is C’s printf function:

int printf (const char *format, ...)

If you’ve never before had the pleasure of using printf, it works


like this: it parses the format parameter, and uses its structure to pop
additional arguments o of the call-stack. You see, it’s the shape of
format that decides what parameters should fill in the ... above.
For example, the format string "hello %s" takes an additional
string and interpolates it in place of the %s. Likewise, the specifier %d
describes interpolation of a signed decimal integer.
The following calls to printf are all valid:
• printf("hello %s", "world"), producing “hello world”,

• printf("%d + %d = %s", 1, 2, "three"), producing “1 + 2 =


three”,
• printf("no specifiers"), producing “no specifiers”.

Notice that, as written, it seems impossible to assign a Haskell-


esque type signature to printf. The additional parameters denoted
by its ellipsis are given types by the value of its first parameter—a
string. Such a pattern is common in dynamically typed languages,
and in the case of printf, it’s inarguably useful.
4 CONTENTS

The documentation for printf is quick to mention that the


format string must not be provided by the user—doing so opens up
vulnerabilities in which an attacker can corrupt memory and
gain access to the system. Indeed, this is hugely widespread
problem—and crafting such a string is often the first homework in
any university lecture on software security.
To be clear, the vulnerabilities in printf occur when the format
string’s specifiers do not align with the additional arguments given.
The following, innocuous-looking calls to printf are both malicious.
• printf("%d"), which will probably corrupt the stack,

• printf("%s", 1), which will read an arbitrary amount of


memory.
C’s type system is insuciently expressive to describe printf.
But because printf is such a useful function, this is not a
persuasive-enough reason to exclude it from the language. Thus,
type-checking is eectively turned o for calls to printf so as to
have ones cake and eat it too. However, this opens a hole through
which type errors can make it all the way to runtime—in the form of
undefined behavior and security issues.
My opinion is that preventing security holes is a much more
important aspect of the types, over “null is the billion dollar
mistake” or whichever other arguments are in vogue today. We will
return to the problem of printf in chapter 9.
With very few exceptions, the prevalent attitude of Haskellers
has been to dismiss the usefulness of ill-typed programs. The
alternative is an uncomfortable truth: that our favorite language
can’t do something useful that other languages can.
But all is not lost. Indeed, Haskell is capable of expressing things
as oddly-typed as printf, for those of us willing to put in the eort
to learn how. This book aims to be the comprehensive manual for
getting you from here to there, from a competent Haskell
programmer to one who convinces the compiler to do their work for
them.
Part I

Fundamentals

5
Chapter 1

The Algebra Behind Types

1.1
1.1 Is
Isom
omor
orph
phis
isms
ms and
and Ca
Card
rdin
inal
alit
itie
iess
One of functio
functional
nal program
programmin ming’s
g’s killer
killer featur
features
es is pattern
pattern matchin
matching,g,
as made possible by algebraic data types . But this this term
term isn’t
isn’t just
just a
catchy title for things that we can pattern match on. As their name
sugge
uggessts,
ts, ther
theree is in fact
fact an algebra behind algebraic data types.
Being comfortable understanding and manipulating this algebra
is a mighty superpower—it allows us to analyze types, find more
convenient forms for them, and determine which operations (eg.
type
typecla
class
sses
es)) are
are poss
possibl
iblee to imple
impleme
ment nt..
To start, we can associate each type with its cardinality—the
numb
number er of inha
inhabit
bitan
ants
ts it has,
has, ignori
ignoring ng bottom
bottoms.s. Cons
Consid
ider
er the
followi
following
ng simple
simple type definiti
definitionsons::

data Void

data () = ()

data Bool = False | True

Void has zero inhabitants, and so it is assigned cardinality 0. The


unit type () has one inhabitant—thus its cardinality is 1. Not to
belabor the point, but Bool has cardinality 2, corresponding to its

7
8 CHAPTER
CHAPTER 1. THE ALGEBRA
ALGEBRA BEHIND TYPES

constructors True and False.


We can write these statements about cardinality more formally:

|Void| = 0
|()| = 1
|Bool| = 2

Any two types that have the same cardinality will always be
isomorphic
isomorphic to one another. An isomorphism between types s and t is
defin
de fined
ed as a pair
pair of fun
functio
ction
ns to and from:

to :: s -> t
from :: t -> s

such that composing either after the other gets you back where
you started. In other words, such that:

to . from = id
from . to = id

We sometimes write an isomorphism between types s and t as s ∼


=
t.
If two types have the same cardinality, any one-to-one mapping
between their elements is exactly these to and from funcfunction
tions.
s. But
where does such a mapping come from? Anywhere—it doesn’t really
matter!
matter! Just
Just pick an arbitra
arbitrary
ry orderin
ordering
g on each type—no
type—nott necess
necessaril
arilyy
corresponding to an Ord instance—and then map the first element
under one ordering to the first element under the other. Rinse and
repeat.
For
For exam
examplple,
e, we can
can de
defin
finee a new type
type that
that also
also has
has card
cardin
inal
alit
ityy 2.

data Spin = Up | Down


1.1. ISOMORPHISMS AN
AND CA
CARDINALITIES 9

By the
the argu
argume
ment nt abov
above,
e, we shou
should
ld expe
expect
ct Spin to be isom
isomor
orph
phic
ic to
Bool. Ind
Indee
eedd it is:
is:

boolToSpin1 :: Bool -> Spin


boolToSpin1 False = Up
boolToSpin1 True = Down

spinToBool1 :: Spin -> Bool


spinToBool1 Up = False
spinToBool1 Down = True

However, note that there is another isomorphism between Spin


and Bool:

boolToSpin2 :: Bool -> Spin


boolToSpin2 False = Down
boolToSpin2 True = Up

spinToBool2 :: Spin -> Bool


spinToBool2 Up = True
spinToBool2 Down = False

Which of the two isomorphisms should we prefer? Does it matter?


In gene
genera
ral,
l, for
for any
any two
two types
types wiwithth card
cardin
inali
ality
ty n,thereare n! unique
isom
isomororph
phis
isms
ms betw
betwee
een
n them
them.. As farfar as the
the math
math goes
goes,, any
any of thes
thesee is
just as good as any other—and for most purposes, p urposes, knowing that an
isomorphism exists is enou
enoughgh..
An isomorphism between types s and t is a proof that for all
intents and purposes, s and t are the same thing. They might have
dierent instances available, but this is more a statement about
Haskell’s typeclass machinery than it is about the equivalence of s
and t.
Isomorphisms are a particularly powerful concept in the algebra
of types. Throughout this book we shall reason via isomorphism, so
it’s
it’s bes
best to get
get comf
comfor
orta
tabl
blee wi
withth the
the idea
idea now.
now.
10 CHAPTER
CHAPTER 1. THE ALGEBRA
ALGEBRA BEHIND TYPES

1.2
1.2 Sum,
Sum, Pr
Prod
oduc
uctt and
and Ex
Exp
ponen
onenti
tial
al Type
Typess
In the language of cardinalities, sum types correspond to addition.
The
The cano
canoni
nica
call exam
examplplee of thes
thesee is Eith er a b, which is either an a or a
Either
b. As a resul
result,
t, the
the cardi
cardina
nalit
lityy (reme
(rememb mber,
er, the
the numb
number
er of inha
inhabit
bitan
ants
ts))
of Eith er a b is the
Either the card
cardininal
alit
ityy of a plus
plus the
the card
cardin
inal
alit
ityy of b .

|Either a b| = |a| + |b|


Either

As you might expect, this is why such things are called sum types.
The intu
intuiti
ition
on behin
behind d addi
adding
ng gene
genera
raliz
lizes
es to any
any data
dataty
type
pe with
with
multiple constructors—the cardinality of a type is always the sum
of the
the card
cardin
inal
aliti
ities
es of its
its const
constru
ructo
ctors
rs..

data Deal a b
= This a
| That b
| TheO
TheOther
ther Bool

We can analyze Deal’s cardina


cardinality
lity;;

|Deal a b| = |a| + |b| + |Bool|


= |a| + |b| + 2

We can also look at the cardinality of Mayb e a. Because


Maybe Because nullar
nullaryy
data constructors are uninteresting to construct—there is only one
Nothing—the
—the card
cardin
inal
ality
ity of Maybe a can
Maybe can be expr
expres
esse
sed
d as foll
follow
ows;
s;

Maybe a| = 1 + |a|
|Maybe
Dual to sum types are the so-called product types. Again, we will
loo
look at thethe canonica ical example first—tht—thee pair type
type (a,
(a, b).
Analogously, the
t he cardinality of a product type is the product of their
cardinalities.

|(a,
(a, b)| = |a| × |b|

To give an illustration, consider mixed fractions of the form 5 12 .


We can represent these in Haskell via a product type;
1.2. SUM, PRODUCT AND EXPONENTIAL TYPES 11

data MixedFraction a = Fraction


{ mixedBi
mixedBit
t :: Word8
, numerat
numerator
or :: a
, denomin
denominato
ator
r :: a
}

And perform its cardinality analysis as follows:

MixedFraction a| = |Word8| × |a| × |a| = 256 × |a| × |a|


|MixedFraction

An interesting consequence of all of this cardinality stu is that


we find ourselves able to express math
mathem
ematatic
ical
al trut
truths
hs in term typess.
termss of type
For
For exam
exampl
ple,
e, we can
can prov
provee that
that a × 1 = a by showing an isomorphism
between (a, ()) and a.
(a, ())

prodUnitTo :: a -> (a, ()


())
)
prodUnitTo a = (a, ()
())
)

prodUnitFrom :: (a, ()
())
) -> a
prodUnitFrom (a, ()
())
) = a

Here, we can think of the unit type as being a monoidal identity


for product types—in the sense that “sticking it in doesn’t change
anything.” Because a × 1 = a , we can pair with as many unit types as
we want.
Likewise, Void acts
acts as a mono
monoididal
al unit
nit for sum
sum type
types.
s. To con
convinc
vincee
ourselves of this, the trivial statement a + 0 = a can be witnessed as
an isomorph
isomorphism
ism between
between Eith
Either Void and a.
er a Void

sumUnitTo :: Either a Void -> a


sumUnitTo (Left a) = a
sumUnitTo (Right v) = absur
absurd
d v · · · · · · · · · · · · · · · · 1

sumUnitFrom :: a -> Either a Void


sumUnitFrom = Left
12 CHAPTER
CHAPTER 1. THE ALGEBRA
ALGEBRA BEHIND TYPES

The function absurd at 1 has the type Voi Voidd -> a. It’s
It’s a sort
sort of
of
blu saying “if you give me a Void I can can give
give you
you anyt
anythi
hing
ng you
you want
want.”.”
Despite this being a lie, because there are no Voids to be had in the
first
first plac
place,
e, we can’
can’tt disp
dispro
rove
ve it.
it.
Func
Functio
tion
n type
typess also
also have
have an encod encodining
g as stat
stateme
ementntss abou
aboutt
cardina
cardinality
lity—th
—they ey correspo
correspondnd to exponentia
exponentializa lization
tion.. To give an
example, there are exactly four (2 ) inhabitants of the type Boo
2
Bool
l ->
Bool. These functions are id, not, const True and const
const True False. Try as
const False
hard
hard as you
you can,
can, but
but you
you won’
won’tt findfind anyany othe
otherr pure
pure func
functi
tion
onss
between Bools!
More generally, the type a -> - > b has cardinality |b||a| . While
While this
this
migh
mightt be surp
surpri
risi
sing
ng at first
first—i
—itt alwa
alwaysys seem
seemss back
backwaward
rdss to me—t
me—the he
argument is straightforward. For every value of a in the domain, we
need to give back a b. But we can can cho
chose any valvalue of b for
for ever
everyy valu
valuee
of a —res
—resul
ulti
ting
ng in the
the follo
followin
wingg equa
equalitlity.
y.

|a - > b| = |b| × |b| × · · · × |b| = |b||a|


  
|a|times

Exerci
Exercise
se 1.2-i
1.2-i
Determine the cardinality of Eit
Eithe
her
r Bool
Bool (Bool
(Bool,
, Maybe
Maybe Bool
Bool)
) ->
Bool.

The
The inqu
inquisisiti
itive
ve read
reader
er might
might wonde
wonderr wheth
whetherer subtr
subtrac
actio
tion,
n,
division and other mathematical operations have meaning when
applied
applied to types.
types. Indeed
Indeed they do, but such things
things are hard,
hard, if not
impossible,
impossible, to express in Haskell. Subtraction
Subtraction corresponds
corresponds to types
with particular values removed, while division of a type makes some
of its values equal (in the sense of being defined equally—rather
than
than havi
having
ng an Eq inst
instan
ance
ce which
which equa
equatetess them.
them.))
In fact
fact,, even
even thethe noti
notion
on of die
diere
rent
ntia
iati
tion
on in calc
calcul
ulus
us has
has
mean
meaniningg in the domain
domain of types
types.. Thou
Thoughgh we wiwill
ll not discus
discusss it
furt
furthe
her,
r, the
the inte
interes
reste
ted
d read
reader
er is enco
encoururag
aged
ed to refer
refer to Cono
Conorr
McBride’s paper “The Derivative of a Regular Type is its Type of
One-Hole
One-Hole Contexts.”[8
Contexts.”[8]. ].
1.3. EXAMPLE: TIC-TAC-TOE 13

1.3
1.3 Ex
Exam
ampl
ple:
e: Tic-T
Tic-Tac-
ac-To
Toee
I said earlier that being able to manipulate the algebra behind types
is a migh
mighty ty supe
superp
rpow
ower
er.. Le
Let’
t’ss prov
provee it.
it.
Imagine
Imagine we wanted to write a game of tic-tac-toe.
tic-tac-toe. The standard
standard
tic-tac-toeboardhasninespaces,whichwecouldnaivelyimplement
like
like this
this::

data TicTacToe a = TicTacToe


{ topLeft
topLeft :: a
, topCent
topCenter
er :: a
, topRigh
topRight
t :: a
, midLeft
midLeft :: a
, midCent
midCenter
er :: a
, midRigh
midRight
t :: a
, botLeft
botLeft :: a
, botCent
botCenter
er :: a
, botRigh
botRight
t :: a
}

While such a thing works, it’s rather unwieldy to program against.


If we wan
wanted
ted to cons
constr
truc
uctt an empt
emptyy boar
boardd for exam
exampl
ple,
e, ther
there’
e’ss quit
quitee
alottofillin.

emptyBoard :: TicTacToe (May


Maybe
be Bool)
Bool
emptyBoard =
TicTacToe
Nothing
Nothing Noth
Nothing
ing Noth
Nothing
ing
Nothing
Nothing Noth
Nothing
ing Noth
Nothing
ing
Nothing
Nothing Noth
Nothing
ing Noth
Nothing
ing

Writing functions like checkWinner turn out to be even more


involved.
Rather than going through all of this trouble, we can use our
know
knowle
ledg
dgee of the algeb
algebra
ra of type
typess to help.
help. The
The first
first step
step is to
perf
perform
orm a card
cardin
inal
ality
ity analy
analysi
siss on TicTacToe;
14 CHAPTER
CHAPTER 1. THE ALGEBRA
ALGEBRA BEHIND TYPES

|TicTacToe a| = |a| × |a| × · · · × |a|


TicTacToe
  
9 times
= |a|9
= |a|3×3
When written like this, we see that TicTacToe is isomorphic to a
function (Thre
(Three,
e, Three
Three) ) -> a,orinitscurriedform: Thre
Threee -> Thre
Threee ->
a. Of course
course,, Three is any
any type
type wi
with
th thre
threee inha
inhabi
bita
tant
nts;
s; pe
perh
rhap
apss it look
lookss
like
like this:
this:

data Three = One | Two | Three


deriving (Eq, Ord, Enum, Bounded)

Due to this isomorphism, we can instead represent TicTacToe in


in
this
this form
form::

data TicTacToe a = TicTacToe2


{ boar
board
d :: Three -> Three -> a
}

And thus simplify our implementation of emptyBoard:

emptyBoard :: TicTacToe2 (Maybe Bool)


Maybe
emptyBoard =
TicTacToe2 $ const $ const Nothing

Such a transformation doesn’t let us do anything we couldn’t


have doneone othotherwi
rwise, but
but it does oes drastical
cally improv rove the
the
ergon
ergonom
omics
ics.. By makin
makingg this
this change
change,, we are rewa
rewardrded
ed with the
entire toolbox of combinators for working with functions; we gain
better compositionality and have to pay less of a cognitive burden.
Lett us not
Le not forg
forget
et that
that prog
progra ramm
mmin
ing
g is prim
primararil
ilyy a huma
humann
endeav
endeavor,
or, and ergonom
ergonomics
ics are indeed a worthwh
worthwhileile pursuit.
pursuit. Your
Your
collea
colleagu
gues
es and
and collab
collabor
orat
ators
ors wi
will
ll thank
thank you
you later
later!!
Exploring the Variety of Random
Documents with Different Content
President-General Quinlan opened the
proceedings, and the Rev. Dr. John J. McCoy said
grace.
A most eloquent speech was delivered by Mr.
Henry J. Breen, son of Hon. Matthew P. Breen, and
he was followed by Hon. John F. O’Connell of
Providence, who spoke concerning the Sullivan
Memorial and the work of the Society in Rhode
Island.
Rev. Dr. John J. McCoy was then introduced, and
his discourse was graceful, eloquent and learned, and
a beautiful tribute to the work of the Society.
Hon. Patrick J. Ryan of Elizabeth, N. J., told in a
most interesting manner of the growth of New York
and of his experiences as a boy romping about on the
present site of the hotel where the banquet was held.
Mr. T. Vincent Butler of New York made a short
speech about our fellow-member, President
Roosevelt, and proposed a toast to his health, which
was drunk amid much enthusiasm.
Dr. M. F. Sullivan of Lawrence, Mass., gave a
number of very practical suggestions as to how the
membership of the Society could be increased and
the sphere of its work extended.
Mr. David Healy of New York spoke of the supreme
importance of the work of the Society in centering the
light of organized, intelligent and painstaking
research upon Ireland’s part in the making of
American history; of her contributions to America’s
greatness, and the proud place which has been
honorably won by her children as an integral part of
American life, American ideals, and American
nationality.
“One of the great disadvantages with which the
Irish element in American life has had to deal,” said
Mr. Healy, “has been the fact that histories and
school text-books, current in the English speaking
world, have been too largely the product of minds
influenced and prejudiced by inherited anti-Irish
animosities and pro-English traditions.
“The Irish have been considered as pre-eminently a
martial race because of their persistent and
unconquerable struggles for a score of generations to
vindicate the principle of Irish nationality.
“It is true that the Celtic race has also been
universally awarded an exalted place in the realm of
poetry, oratory and song, as well as in devotion to
family and in faithfulness to principle. It remains for
the American Irish Historical Society to show other
and equally important and admirable characteristics
of the Irish race, and to point to other fields wherein
Irishmen have distinguished themselves in meeting
the current and pressing problems of America’s rapid
and unparalleled development.
“It remains for us to realize and to show to others
that not only was it the Irishman’s pick that brought
the earth’s hidden treasures to the surface, his shovel
that made ready for the iron rail across the continent,
but it was Irish brain and enterprise largely that
developed the mines and constructed the steel
pathway between the East and the West, thus making
a national unit qualified and competent to deal with
the nations of the world.
“In the great life current of American nationality,
the rich red blood of the Celt has been a dominant
and fructifying tributary.
“It also remains for us to realize our shortcomings
and to aim for the highest ideals, not to be content
with a leading place in the world of military renown,
financial, industrial and commercial enterprise. We
should earnestly seek correspondingly high places in
the realm of philanthropy, moderation and universal
brotherhood.”
During the evening the Sullivan Memorial
Committee having in charge the erection and
dedication of a bronze memorial at the State House
in Rhode Island to Maj.-Gen. John Sullivan, made a
report through Judge Lee, its chairman, showing
substantial progress and an intention to dedicate the
memorial some time during the present year.
Mr. Dennis H. Tierney made stirring remarks
concerning “The Star Spangled Banner” as a patriotic
song taken as a whole, and deplored the disposition
of so many public bodies to leave out parts of it.
After remarks by other members the company
dispersed, having participated in one of the most
entertaining and instructive banquets ever held by
the Society.
Thomas Hamilton Murray,
Secretary-General.
THE SULLIVAN MEMORIAL.

Distinguished Gathering of Members and Guests


Present—Proceedings in Full.
An event of much historical significance to Rhode
Island, and indeed to the entire country, took place
under the auspices of the Society at the Rhode Island
State House on Wednesday, December 16, 1908,
when an impressive bronze memorial was dedicated
to the memory of Major-General John Sullivan, one
of Rhode Island’s Revolutionary heroes.
The memorial, which most appropriately
commemorates the services of General Sullivan to his
race, his country and his State, is placed in a fitting
position in the broad corridor of the main entrance to
the capitol. Large, beautifully designed and in every
way worthy of its mission, it immediately claims the
attention of everyone who enters the State House. It
has already been the object of favorable comment
from many distinguished people, and is
acknowledged to be a credit not only to the memory
of the distinguished soldier, but also to the Society
through whose efforts it was placed in its present
position.
The exercises on the day of the unveiling were in
every way worthy of such an occasion. People of
distinction in every walk of life were present, all the
historical organizations of the State were represented
by officers and members, and addresses befitting the
event were delivered by men of prominence in public
life and in historical research. Col. David C.
Robinson, of New York, a well-known student of
history and a most eloquent speaker, was the orator
of the day, and inspiring speeches were made by Dr.
Francis J. Quinlan, of New York, President-General
of the Society; Gov. James H. Higgins, of Rhode
Island; Governor-elect Aram J. Pothier; ex-Governor
Charles Warren Lippitt; Mayor Patrick J. McCarthy,
of Providence; and Gen. William Ames, chairman of
the State House Commission. Hon. Thomas Z. Lee, of
Providence, chairman of the Sullivan Memorial
Committee, presided. The exercises took place in the
presence of a large gathering and one thoroughly
representative of the public and social life of the city
and State.
MR. THOMAS ZANSLAUR LEE,

Secretary-General of the American Irish Historical


Society.
Following the dedicatory exercises luncheon was
served at the Narragansett Hotel, the Society’s
headquarters, and this also was followed by a
number of brief addresses from well-known Rhode
Islanders and members of the Society from other
States.

The proceedings at the State House began at noon,


Judge Lee making the opening address. He said:

“Honored Guests, Members of the American Irish Historical


Society, Ladies and Gentlemen:
“We are assembled in the Rhode Island State House today to
dedicate a memorial in honor of Maj. Gen. John Sullivan whose
service to the country and this State during the war of the Revolution
is familiar to every American, and whose career as a soldier,
statesman and jurist will be eloquently depicted by those who will be
presented to you later. My remarks will be confined to a short history
of the American Irish Historical Society under whose auspices the
memorial was erected, and a reference to the movement and spirit
which prompted the work.
“The American Irish Historical Society was organized in Boston,
January 20th, 1897. Certain gentlemen interested in historical work,
believing that proper recognition had not always been given by
historians and others to the part taken in the settlement,
foundations, upbuilding and general affairs of the United States by
those of Irish descent, brought forth the idea of a society, national in
its scope, that should be devoted to making better known the Irish
Chapter in American history, by giving plain recitals of facts,
correcting errors, supplying omissions, discouraging prejudice,
establishing right and truth, and giving rightful place and just due to
historical matters concerning American citizens of Irish nativity,
blood or extraction. Invitations were sent out by these gentlemen,
and an enthusiastic meeting took place, at which representatives
from seventeen States were present; and the following were elected
the first officers of the Society:

“Rear Admiral Richard Worsam Meade, U. S. Navy, of


Washington, President-General; Mr. Osborne Howes of
Massachusetts, Vice-President-General; Hon. John C. Linehan of
New Hampshire, Treasurer-General; Thomas Hamilton Murray of
Rhode Island, Secretary-General; and Thomas B. Lawler of New
York, Librarian and Archivist.
“The first Executive Council consisted of the foregoing and Mr.
James Jeffrey Roche of Boston, Hon. Robert Ellis Thompson of
Philadelphia, Hon. Theodore Roosevelt of New York, Hon. Edward
A. Moseley of Washington, Mr. Augustus St. Gaudens of New York,
Mr. Joseph Smith of Lowell, T. Russell Sullivan, a direct descendant
of General Sullivan, of Boston, and Hon. Maurice F. Egan of
Washington.
“The first Board of State Vice-Presidents was as follows: Maine,
Mr. James Cunningham of Portland; New Hampshire, Mr. T. P.
Sullivan of Concord; Vermont, Mr. Thomas W. Moloney of Rutland;
Massachusetts, Mr. Osborne Howes of Boston; Rhode Island, Mr. M.
Joseph Harson of Providence; Connecticut, Mr. Joseph F. Swords of
Hartford; New York, General James R. O’Beirne of New York City;
New Jersey, Hon. William McAdoo, Assistant Secretary of the Navy,
of Jersey City; Pennsylvania, General St. Clair A. Mulholland of
Philadelphia; South Carolina, Ex-United States Senator M. C. Butler
of Edgefield; Georgia, Ex-United States Senator Patrick Walsh of
Atlanta; Ohio, Rev. George W. Pepper of Cleveland; Illinois, W. J.
Onahan of Chicago; Michigan, Ex-Congressman Thomas A. E.
Weadock of Detroit; Minnesota, Mr. Daniel W. Lawler of St. Paul;
Missouri, Mr. Richard E. Kerens of St. Louis; District of Columbia,
Mr. J. D. O’Connell of Washington.
“The work that the Society has undertaken is worthy of the
sympathy and aid of every American who is interested in the past,
present and future of this, the greatest country on earth; and in doing
its work the watchwords of the Society are Fidelity, Truth and Honor,
and we feel and know what the influence and inspiration of these
words mean.
“One of the preambles in the Constitution reads: ‘While we as loyal
citizens of this Republic are earnestly interested in all the various
phases of its history, we feel that we should be false to its honor and
greatness and recreant to our own blood if we did not make a serious
effort to leave to those generations which will follow us, a clearer and
better knowledge of the important work done by men and women of
the Irish race in the United States.’
“The broad scope of our work may be comprehended from a
statement of our objects and purposes:

“(1) The study of American history generally.


“(2) To investigate, especially, the immigration of the people of
Ireland to this country, determine its numbers, examine the sources,
learn the places of settlement; and estimate the influence on
contemporary events in war, legislation, religion, education and
other departments of human activity.
“(3) To examine records of every character, wherever found,
calculated to throw light on the work of the Irish element in this
broad land.
“(4) To endeavor to correct erroneous, distorted and false views of
history, where they are known, and to substitute therefor the truth of
history, based on documentary evidence, and the best and most
reasonable tradition, in relation to the Irish race in America.
“(5) To encourage and assist the formation of local societies in
American cities and towns for the work of the parent Society.
“(6) To promote and foster an honorable and national spirit of
patriotism, which shall know no lines of division, which shall be
based upon loyalty to the laws, institutions and spirit of the Republic
to whose upbuilding the Irish element has unselfishly contributed in
blood and treasure, a patriotism whose simple watchwords shall be
‘true Americanism’ and ‘human freedom,’ and which has no concern
for any man’s race, color or creed, measuring him only by his
conduct, effort and achievement.
“(7) To promote by union in a common high purpose, a sincere
fraternity, a greater emulation in well doing, a closer confidence and
mutual respect among the various elements of the Irish race in
America, that by putting behind it the asperities of the past, it may
unite in a common brotherhood with its fellows for the honor of the
race and the glory of the Republic.
“(8) To compile the results of its historical investigations in
suitable literary form; to print, publish and distribute its documents
among libraries, educational institutions and its own membership
with a view to the wide dissemination of historical truths, and in
order that such data may be placed within the reach of historians and
other writers and readers.
“(9) To discriminate every paper, sketch and document bearing on
the work of the Society before the same is accepted and given official
sanction, in order that its publication may be a guarantee of its
historical accuracy; to do its work without passion or prejudice, to
view acknowledged facts in the true scientific historical spirit; and,
having reached the truth, to give it to the world.

“Some two years ago the movement for the


erection of this memorial was started. The first
suggestion came from Mr. Thomas Hamilton Murray,
the late honored Secretary-General of the Society.
The Rhode Island members at once manifested a
deep interest, formed themselves into a committee,
and, in due time, solicited among their number
subscriptions for this memorial. These subscriptions
came in very satisfactorily, and, when we were
assured that it was possible to erect a suitable
memorial, a sub-committee of the general committee
conferred with the Board of State House
Commissioners, who assigned to us the most
appropriate space in the State House, beside the
cases of flags carried by Rhode Island regiments in
the different wars.
“The memorial has been erected with the aid of
Rhode Island subscriptions, with one or two
exceptions. It was designed by the brilliant young
sculptor, Mr. John G. Hardy, under whose direction
it was executed by the W. J. Feeley Company, of
Providence.
“I now take great pleasure in behalf of the
American Irish Historical Society and in behalf of its
committee, in presenting to the State of Rhode Island
the Sullivan memorial, which Mr. Hardy will now
unveil. (At this point the flags draping the memorial
were drawn aside by the sculptor.)
“And now I have the great honor to present to you
a gentleman well-known and highly-honored by all
Rhode Islanders, one who has shown deep interest in
this, as in all other worthy projects, Hon. James H.
Higgins, Governor of Rhode Island.”
Governor Higgins spoke as follows:

“Ladies and Gentlemen: In behalf of the State of Rhode Island, I


am not only pleased but proud indeed to accept this splendid
memorial. Rhode Island has a particular interest in the career and
achievements of General Sullivan. He was delegated to the command
of the forces in Rhode Island largely through the recommendation of
General Greene, the greatest soldier of all in the Revolution next to
Washington. Through the joint recommendations of Washington and
Greene, Sullivan was placed in command of the forces in this State.
“There was perhaps no State in the Union which, in proportion to
its size and population, suffered more of the hardships of that great
struggle than our own. Some historians have suggested that one
section of our State, Newport and the Island of Rhode Island, have
never recovered from the blow dealt it through the long occupation
of that section of the State by the British forces. We of Rhode Island,
therefore, have a particular interest in the efforts of General Sullivan
to expel the British from this State.
“We are proud, therefore, to know that the American Irish
Historical Society has taken this matter up and has shown such
active interest in perpetuating the memory and the exploits of
General Sullivan. I am sure that I can say on behalf of our united
citizenship that the State appreciates this activity, this patriotism, on
the part of the American Irish Historical Society, and we want to say
to you, sirs, that the fruit of your interest—this memorial—will ever
be preserved by our State as a remembrance of his splendid
achievements, as well as of the generosity and the patriotism of the
organization which prompted it. May your activity, my friends, be
continued throughout the length and breadth of the land and
throughout the entire period of your career in the same creditable
and patriotic manner that has characterized your work concerning
General Sullivan.
“Again, sirs, I am pleased to accept in behalf of our State this
splendid remembrance, to assure you of our profound appreciation,
and to say that it shall ever remain as a memento of your patriotism
and character, of the gratitude and appreciation of our good State, as
an inspiration to all future generations and to all visitors to this
splendid Capitol, of the value and eternity of that thankfulness which
a grateful people feel for those who serve them well.
“It is now my pleasure to turn the memorial over to General
William Ames, the Chairman of the State House Commission, in
whose trustworthy hands this monument will be placed and from
whom I am sure it will receive the same careful and patriotic
attention that all his other duties have received in connection with
the management of our splendid State Capitol. I am pleased,
therefore, to introduce to you one of our most honored fellow
citizens, General William Ames, who will accept in behalf of the State
House Commission.”

General Ames responded as follows:

“Your Excellency, Members of the American Irish Historical


Society, Ladies and Gentlemen: As Chairman of the Commission
having in its care and keeping this beautiful State House it is my
privilege to bid you welcome here today. We are assembled, not for
an ordinary occasion, but for an extraordinary one. We are here to
inscribe upon this marble wall the name of one who was patriot,
soldier and statesman, the commander who planned and fought the
Battle of Rhode Island in 1778.
“General John Sullivan passed on long years ago to make his final
report to the great Commander of us all. Yet we have treasured his
memory, and through the years it has grown ever dearer to the hearts
of all patriotic Americans—to us of Rhode Island more than all. And
now that love has found fitting expression in this memorial, which
shall commemorate through the coming ages his patriotism, his
devotion, and his loyal services to his country.
“A State can perform no more graceful act than to make public
record of the deeds and accomplishments of its famous sons. It
therefore gives me great pleasure, and I deem it a high honor, to
accept for the State House Commission the custody and care of the
beautiful memorial placed upon these walls by the American Irish
Historical Society.”

At the conclusion of General Ames’ acceptance


Chairman Lee introduced Mayor McCarthy in the
following words: “The thanks of the American Irish
Historical Society are due and are hereby tendered to
General Ames and to Hon. James M. Scott and Col. J.
Edward Studley, the other members of the Board of
State House Commissioners, for their great courtesy
to us. It was to them we first addressed ourselves for
permission to place our memorial to General Sullivan
in the State House, and when it was ready for its
permanent position a few weeks ago, we went to
them again concerning the dedicatory exercises. Our
comfortable seating was provided for, the freedom of
this beautiful capitol extended us and an ample force
of employees placed at our disposal. We may well be
grateful for the uniform courtesy and consideration
that marked all the Commission’s dealing with our
Society.
“The Secretary of our committee is a very worthy
member of the Society. As I happened to be the
Chairman, it was my privilege to sign my name over
his in issuing the invitations. It is the first time I have
ever had an opportunity of putting my name before
that of His Honor the Mayor, and I enjoyed the
opportunity. But now, after doing his work as
Secretary of the committee very faithfully, he has
tendered his resignation, which we have most
regretfully accepted, in order that he might do his
duty as Chief Executive of the City of Providence. I
have the honor to introduce to you our esteemed
fellow-member, Hon. Patrick J. McCarthy of
Providence, who will, I am sure, extend to us a warm
welcome to the principal city of the State over the
destinies of which he presides so ably.”
Mayor McCarthy said:

“Mr. Chairman, Fellow Members of the American Irish Historical


Society, Ladies and Gentlemen: I am deeply sensible of the honor my
official position and duty brings me on this occasion as Mayor of
Providence in greeting the representatives of The American Irish
Historical Society and its distinguished guests from many states; I
tender you a ‘Providence Welcome,’ and the freedom of the city.
“I thank the Society for its munificent gift of the beautiful bronze
memorial, which commemorates the heroic deeds of Major General
John Sullivan of the Continental Army and his services to his native
State (New Hampshire) as citizen, legislator, jurist and governor, and
also to the United States as a member of Congress.
“The people of Providence thank the State House Commissioners
for allotting space for the memorial in the Capitol Building of Rhode
Island; it is an appropriate place for a memento of the hero of the
Battle of Rhode Island. The good deeds of men live after them.
General Sullivan’s life was spent in the service of his state and
country. He was generously endowed by nature, with the mental and
physical qualities that are characteristic of his race, which enabled
him to perform his duty on the field, on the bench, as chief
magistrate of his State, and as a citizen, courageously and zealously
with loyalty to God and country—seeking honor only in the discharge
of duty.
“The history of his life work survives him. We are assembled to
honor his memory. The memorial you have this day placed in this
State House is a page in bronze, of the history of the early struggles
of our countrymen for National Independence, equal rights, and
freedom—a page which future generations will read with inspiration
to emulate the honorable career of General Sullivan.
“We honor ourselves in dedicating this monument to his memory.
Providence is grateful to the Society for possession of it within the
city, and is modestly proud of the fact that it is the product of a
Providence artist and establishment.
“The dedication of permanent monuments in grateful recognition
of the noble service of good men inspires others to heroic deeds and
sacrifices, and perpetuates the history of such men and their
achievements.
“The American Irish Historical Society, in placing this beautiful
memorial in Rhode Island, commemorates one of the early battles in
support of the Declaration of Independence and for national
separation of the Colonies from Great Britain, fought by an American
General of the Irish race, ever loyal to the cause of freedom and
equality and commends the history of his life, and the history of the
Irish race in America to all men of good will.”

Chairman Lee: “A generous response to our invitations has been


received, nearly all our invited guests being present. We have
received letters of regret, however, from Rev. W. H. P. Faunce,
President of Brown University, Hon. Asa Bird Gardiner, Rt. Rev.
Mathew Harkins and one or two others whose letters are not this
moment before me. Our fellow-member, the President of the United
States, in a letter to us, tenders his regrets at being unable to be
present, and cites urgent business at home as the reason. Judging
from the accounts in the morning papers about his trouble with the
yellow journals, I take it he is pretty busy at this time in Washington.
“We have letters of regret from other members of the Society who
are unable to be present. I will read the names only. Rt. Rev. Philip J.
Garrigan, Bishop of Sioux City; Rt. Rev. M. J. Hoban, Bishop of
Scranton; Hon. W. Bourke Cockran of New York; John Moriarty of
Waterbury, Conn.; J. B. Spillane of New York; M. C. O’Brien, M. D.,
of New York; James H. Devlin, Jr., of Boston, Mass.; Rev. John J.
McCoy, LL. D., of Worcester, Mass.; John W. Bourlet of Concord, N.
H.; Rev. Gerald P. Coghlan of Philadelphia; Hon. Willis B. Dowd of
New York; Richard Worsam Meade of New York; Patrick Gallagher
of New York; Edward J. Brandon of Cambridge, Mass.; J. C. Griffin
of Skowhegan, Me.; W. P. Regan of Lawrence, Mass.; W. J. O’Hagan
of Charleston, S. C.; John J. Slattery of Louisville, Ky.; John F. Doyle
of New York; P. F. McBreen of New York; John J. Keenan of Boston,
Mass.; William Francis Byrnes, M. D.; Hon. J. C. Monaghan of New
York; Wiliam B. Sullivan of Boston, Mass.; Hon. P. J. Ryan, Mayor-
Elect of Elizabeth, N. J.; H. M. Cox, M. D., of New York; Dr. George
McAleer of Worcester, Mass.; William Gilbert Davies; Charles V.
Dasey of Boston, Mass.; Finley Peter Dunne of Chicago; Hon. John J.
McDonough of Fall River, Mass.; Eugene Lynch of Boston, Mass.;
Stephen Farrelly of New York; Mitchell McDonahue; Henry L. Joyce
of New York; Major E. J. O’Shaughnessy of New York; Lawrence
Clancy of Oswego, N. Y.; Rt. Rev. Thomas J. Conaty, Bishop of
Monterey, Los Angeles, Cal.; Judge Mathew Breen of New York;
Capt. James Connolly of Coronado, Cal.; Gen. A. G. Malloy of El
Paso, Texas; John J. Daly of New York; Hon. Edward A. Moseley of
Washington; Judge Victor J. Dowling of New York; Rev. M. J. Cooke
of Fall River and Rev. Cyrus Townsend Brady of Toledo, Ohio.
“Before presenting the orator of the day I desire to say to all
members who have not visited the Society’s headquarters at the
Narragansett Hotel that luncheon will be served there after the
ceremonies here; delegates of all the organizations represented in
response to our invitation are also cordially invited to join us at
luncheon. The headquarters are in room 10 at the hotel, and
luncheon will be served in the main dining-room immediately upon
our arrival there.
“The Society is fortunate in having secured for the principal
speaker today a gentleman who knows perhaps more about the life
and works of General Sullivan than does any other in the United
States; a statesman whose record is widely known, and whose voice
has been heard in discussion of historical and other matters in the
New York capitol at Albany on many occasions. The son of a former
governor of New York, he has always been identified with New York
institutions and New York laws. Through his efforts the Legislature
of that State recently appropriated $10,000 for the purpose of
erecting a suitable memorial to General Sullivan, and, while the
purposes of that resolution have not yet been fulfilled, it will be but a
short time before a fitting tribute is paid by the State of New York to
the memory of Major General Sullivan. And the credit for that tribute
will be due in large part to the gentleman I now have the honor to
introduce, Col. David C. Robinson, of Elmira, N. Y.”

Colonel Robinson spoke as follows:

“Mr. Chairman, Your Excellency the Governor, Members of the


American Irish Historical Society, Ladies and Gentlemen: I should
do less than justice to the emotions of the hour if I did not, at the
outset, express my high appreciation of and my profound thanks for
the honor done me in the invitation from your Society to voice our
mutual sentiments upon so important an occasion as this. It is an
honor to be invited as a spectator to take part in such a ceremony as
this; it is a higher honor to be accounted worthy even by a few to say
a word on such an occasion; it is honor most of all that I have your
unanimous invitation to say that which I may be able to in memory
of one of the noblest and purest characters on whom the sun of
history has ever shone.
“It has been the habit of my life, my friends, to speak without a
note; the professional training of many years has made it easier. I do
remember many, very many things about Major General John
Sullivan and his life; I do not remember all that I should mention, for
the line is long, and I am, therefore, contrary to my usual custom,
obliged to ask you to bear with me while I refresh my recollection
from time to time with a memorandum of some of the most
distinguished services with which this man’s life was filled, to the end
that I may impress the lesson which speaks from this memorial,
which speaks from the long-drawn procession of brave and good and
kind deeds with which the life of the one whom we commemorate
today is surrounded.
“And first, before I enter on that which I would say of this
memorial and of him to whose memory it is dedicated, I want to
congratulate this Society on that which it has even in the few years of
its existence accomplished, and on the labors, increased in volume
every year, by which it makes known the Irish chapter in American
history.
“To trace that which we owe to the line of blood of which this man
was one of the most illustrious examples, is a duty which belongs to
every student of American history. Let us find, if we may, wherein lay
that in which he so far exceeded most of his fellowmen. Let us make
it a lesson not alone to say that this man was one of the greatest of
American Irish or Irish Americans, but that he illustrated a trait of
character which Americans and Irish American citizens all ought to
follow, ought to teach their children to follow, ought to endeavor to
perpetuate in the thoughts, the work, the labors of this land.
“Now we are met principally to do honor to the memory and the
merits of a brave and good man; that is our purpose; but in our acts
and words today, my friends, we do honor not only to him and to his
memory, but we do honor to ourselves and our countrymen. He
belongs to us and we appreciate it. The laurels which we lay on the
graves of such as he, who periled life, limb, fortune, happiness and
health that we might enjoy the blessings which are ours today, are
laurels piled upon our own characters, our own qualities.
“From this beautiful tablet, so fittingly placed in honor of him,
whose name in this hour fills all our hearts, the veil has just fallen in
your sight. I do not envy that American who, at such a time as this,
does not feel his heart swell with patriotic pride at the thought of
what this graven monument means to us and ours.
“A thousand recollections sparkle in the chambers of memory as
we recall the chivalry, the worth, the dauntless courage and self-
denying loyalty of him whose heart, stilled in its own earthly
tenement for more than a hundred years, yet lives and throbs and
pulses in the hearts of every lover of his land and of human liberty
the wide world around; and, although appreciating to the fullest
extent all that your Mayor has so well said and the Chairman so ably
suggested of the beauty of this memorial, I may be pardoned for
saying that no work of art, no accomplishment of high design, no
costly metal, no skilful chiseling, no beautiful moulding, can make a
memorial worthy of such a man as was Major General John Sullivan.
“For when I think of what he was and what he did, when there
rises to my sight the sacrifice and effort, the combat and the stern
endurance, the privation and the grief, the sorrow and the pain,
which marked his labor and his life throughout the years which
spanned the rise of freedom, yea, the hope of men upon this
continent, I feel sure that pen may not write, voice may not sound,
nor can the chisel of art produce token worthy of his high deserving.
“I would that the task of voicing our sentiments upon this
occasion, the impressions of this hour, had fallen to other and to
abler hands than mine. I wish that some peerless orator, born of that
great race from which he sprang, might tell us here whence came the
greatness, the nobility, the grace and loveliness which were so
gloriously his, and, in telling that, might teach our children how he
came to that high state of manly quality which all the world now
knows was his.
“But, friends of this great Society, whose well-bent efforts have
done so much to give deserving heroes the credit which was rightly
theirs, I know you will not let the awakened and quickening
memories of this great soul for one moment hesitate in their progress
toward wider and better appreciation.
“I know that my own shortcomings will be more than
complemented by your larger opportunity of bringing within the
circle of his admirers every patriotic citizen of this Republic. Nay,
more, I hope the day will come when every State House in the land
shall hold a tablet such as this, when every schoolboy shall read
lessons from his life, when every human being who seeks partnership
and title in the freedom of his kind shall, in his memory, cherish the
name of Major General John Sullivan as one who deserves a niche
unshadowed and a fame unscarred among the scanty array of those
great souls whom the genius of Liberty proudly calls her own.
“This is not the fulsome word of hyperbole; it is not the sounding
tinkle of rhetoric or idle eulogy. It is the measured testimony of those
who have read aright the history of the great struggle for
Independence, and have found therein no light or shadow in which
the great soul of Major General Sullivan did not sparkle with the
luster of a flawless diamond. And in this hour, beneath the lofty
dome henceforth to shadow this memorial, in this free atmosphere
which seems even now to echo with the guns he fired against his
country’s foes, in this bright light, not purer than the soul he wore
upon his sleeve, let us trace out a few of those strands of character
which made him what he was, and, in our speaking, draw some
inspiration from a few of the many debts which Liberty and our
common country owe to him.
“Ah, my friends, the account is long. We find him early trained as a
lawyer, and at the age of 32 Major of the New Hampshire Regiment;
in the spring of 1774, a member of the Provincial Assembly of New
Hampshire; in September of the same year and in 1775, a delegate to
the Continental Congress, by which he was in June, 1775, appointed
a Brigadier-General, and in 1776 a Major-General.
“Yet even while he was, at 34, only a New Hampshire Major, he
had accomplished perhaps the most daring personal feat of the
Revolution in the seizure of the powder and arms at Fort William
and Mary in Portsmouth Harbor. Do you realize what that meant?
Little more than a boy, anticipating, as he always anticipated,
troubles to come, he dealt a crushing blow to the greatest power on
earth, a boy with a dozen companions, and he sounded in that one
daring act the keynote of that grand chorus of Liberty whose majestic
final chords were heard in the surrender of Cornwallis at Yorktown.
“I challenge the world to find a busier or more useful life than his
for the five years from 1774 to 1779. No wonder, my friends, that no
memorial can do justice to this. We find him on Winter’s Hill at the
siege of Boston, working with all the energy of a vigorous manhood
and high purpose; again at Portsmouth to advise and assist in
warding off a menaced attack from the British fleet; thence hastily
ordered to New York to aid General Putnam with a powerful
detachment.
“The pressing needs of the imperiled American army in Canada
caused General Washington, in the spring of 1776, to hurry him off
with six regiments to join its Commander at the earliest possible
moment. Do you realize, my friends, what a journey to Canada with
six regiments—a hasty journey—meant in those days? Yet Sullivan
was there, only to see the death of the Commander whom he had
been ordered to assist, from a malignant attack of smallpox; and
himself suddenly succeeded to the place of Chief Commander of the
entire expedition.
“Nothing could exceed the vigor and discretion of his work as
Commander of this most difficult expedition. Washington wrote of
him at this time—and I love to quote of this man who has always
been my historical ideal the words of the greatest mind in war and
peace this country has ever known—Washington wrote of him at this
time: ‘He is active, spirited and zealously attached to the cause. His
wants are common to us all. He wants experience to move upon a
grand scale, for the limited and contracted knowledge which any of
us have in military matters stands in very little stead.’
“But Washington’s most competent biographer, Washington
Irving, declares with emphasis and truth: ‘This want was
overbalanced on the part of General Sullivan by sound judgment,
some acquaintance with men and books, and an enterprising genius.’
“It is a source of profound regret to the thoughtful student of
American history that General Sullivan was not left in charge to work
out the problem of the Canadian expedition. True, he was only thirty-
six years of age and had had but limited experience, but his
successful combinations of a few years later leave it more than
possible that, with him as a leader, the whole of Canada might have
been added to the United States even at that early day, and the
Revolution there terminated in half the time it finally lasted.
“This was not destined so to be, for Congress somewhat hastily
decided to commit the command of the Northern army to the much
older but, as many of us now believe, far less competent hands of
General Gates. I should not do justice to General Sullivan’s character
if I did not concede that this replacement caused him some hurt, and
I might say grief, but his magnanimous and instant efforts in the very
moment of his return from Canada to serve his country by taking up
as temporary Commander the perilous work on Long Island which
General Greene had been compelled by illness to lay down, showed
the soldier, the gentleman and patriot as no less trying circumstances
could.
“In the midst of the carnage of the disastrous battle of Long Island,
Sullivan was taken prisoner. At once paroled and soon after
exchanged, we find him in December, 1776, hastening to join General
Washington.
“Let me now turn from the track of this all too historical resumé to
call your attention to the fact that, when Lord Howe paroled General
Sullivan, desirous then of accelerating and possibly terminating the
Rebellion without severance with the colonies, he selected John
Sullivan as the honored representative of the British Government to
convey his message to George Washington, and General Sullivan,
under his own parole, brought from Lord Howe to George
Washington the propositions which Lord Howe felt he could entrust
to no more worthy hands than those of this man who was the
absolute and the untiring enemy of Great Britain. That is a
testimonial to General Sullivan whose place no monument can take.
“In December, 1776, he hastened to join General Washington. On
the morning of the attack of Trenton, after a night of storm and cold
so bitter that some of his men were frozen to death and many of his
guns were rendered wet and useless, he reported to Washington the
defective condition of his muskets, as was his duty, but was ordered
to advance and charge, which he did with so much effect that his
regiment was really the first in action at the lower end of the town.
“Next we find him, September 11th, 1777, on the disastrous but
glorious field of Brandywine, every duty discharged with
promptness, cool courage and sound discretion and judgment, and
even in the closing hours of that struggle his was the foremost figure
in the desperate center of the fray.
“Brandywine and its disappointing finish was scarcely over before
the conflict at Germantown involved him with his division in another
desperate struggle, where an unfortunate and needless delay by
General Knox and the sudden rising of a dense and impenetrable fog
snatched from his hands a victory earned and well earned by every
exhibition of soldierly quality a commander could give. And even in
the hour of keenest personal disappointment, balked of a victory he
had richly earned, a victory which would have set his name ringing
around the world as its chief author and cause, his thoughts were not
of himself, but of the personal danger to Washington to whom he
gave the lifelong devotion which only lives in the breasts of noble
men.
“Without a pang or plaint of his own peril and disappointment, he
writes: ‘I saw with great concern our brave Commander-inChief
exposing himself to the hottest fire of the enemy in such a manner
that regard for my country obliged me to ride to him and beg him to
retire.’ And in the longer account of which these words are a part, my
friends, not a suggestion can be found or guessed of the added peril
which the writer himself freely braved in the efforts to remove his
Chief from danger.
“This hasty and inadequate resumé of his service in the first two
years of the Revolution brings us to the great military operation of
which he was the chief and on which will always rest much of his
fame—the investment of Rhode Island and the series of movements
of which the State and coast of Rhode Island formed the picturesque
theater.
“The enterprise was a favorite one with Washington, who hoped,
indeed, that it would emphasize the French alliance at the outset by
an overwhelming and successful effect of an attack on the British
army almost within the sound of our voices. Its success was very dear
to Washington’s heart, and for it he chose three officers perhaps
more closely in his confidence and affection than any others in the
Revolutionary Army. Sullivan was in chief command, with Greene
and Lafayette as equal subordinate assistants, each having a division
comprising as nearly as possible half of the army.
“The plan of operations had been agreed upon between
Washington and the French Commander, and the conflict was laid
out to be, as it should have been, the first great effort of the allied
French and American forces against the British army of invasion.
“I am speaking to an audience whose youngest members should
and probably do know more of the details of these military
movements than I can ever hope to know.
“From first to last, down to the finest particular of necessary
prevision, General Sullivan was more than ready. All that a
commander could do to insure success, he had accomplished so well
that the only criticism made of his actions was that he had seized the
British works opposite the north end of the island one day ahead of
time. At this, the French General who had expected a joint attack to
be made the next day professed to believe his notions of military
etiquette had been shocked, but, as no harm resulted and a distinct
gain in time had been effected, he had small foundation for his
complaint, which was soon practically abandoned.
“There had been an excellent opportunity to make the joint
undertaking a magnificent success. If, as is now apparent, the attack
had been made in the latter part of July as it might easily have been
in view of Sullivan’s perfect preparations and the presence of the
French fleet, it is probable that the war would have reached a
complete and glorious close almost within sight of the ground upon
which we stand today. Postponed as it was from day to day until
August 10th, the British were given time to reinforce their fleet,
hasten it to Newport, and there engage the French fleet in dilatory
manœuvering which used up days of precious time and completely
dissipated all hope of substantial assistance from the French
warships. The expected, or that which should have been expected by
the naval commanders, soon happened; many of us who have spent
much time around here would have expected it to happen.
“About the twentieth of August, one of those storms for which the
region of Point Judith is famous, set in with almost unexampled fury.
Land and water forces were alike put out of condition for offensive or
defensive operations. The French fleet limped away to Boston to
refit, and Sullivan, deeply chagrined at the utter failure of his naval
auxiliaries to render any assistance, set to work to protect his army
and extricate it from a position made perilous by the departure of its
entire marine support and the consequent desertion of most of his
militia.
“The story of his great achievement in retiring his entire force in
the face of a vastly superior English army, of the masterly retreat
covered by his most skilfully selected position at Butts Hill, as I
believe it is called—as to its proper name, I shall not attempt to
correct a Rhode Island audience—a retreat effected finally so
completely that not a man was left behind and not a single article
lost, while, in the course of that retreat, signal and marked
punishment was inflicted upon the British army, will ever read like a
romance of model leadership, and, if General John Sullivan had no
other memory, my friends, than of what he did within a radius of
sixty miles of this Capitol, his fame could be no less great and no less
enduring than it is, and, what is more, would be richly deserved.
“Thus briefly, as becomes my scanty time, I have sketched the
work of John Sullivan to the close of 1778. I have not made the
motive of my story clear if it has not already appeared that this man
was greater in the hour of undeserved disappointment than most
men in the exaltation of victory. Again and again, the fruits of
deserved and brilliant success were held to his lips, only to be dashed
away by the folly of the foibles of some weaker spirit necessarily
entangled in his plans. Yet never for an instant did he yield to the
despair and mortification which would have sunk less noble souls.
Each disappointment seemed to but nerve him to stronger and more
brilliant efforts. And herein, my friends, to my mind, is illustrated
and should be made prominent one grand characteristic which we
have taken from the noble Irish race. The patience under
disappointment which Major General John Sullivan illustrates, the
patience under disappointment which again and again was
manifestly the fault of men to whom he never gave a word of rebuke
or complaint, the steadfast iron determination with which he set to
work instantly to repair the ruin that some, associated in common
with him, had wrought, is the brightest leaf in the chaplet which
America has put upon his grave.
“It is an honor to belong to that grand old race, aye, even to hold
one drop of Irish blood in your veins, but, good friends all, with or
without it, I am proud to testify to what Irish friendship, Irish loyalty
and the matchless Irish courage can do. No man ever knew as I have
known what Irish friendship is, no man ever knew as I have known
what Irish hospitality is, no man ever knew as I have known what
Irish loyalty and patience is, without bowing in humble respect to it,
whether he drew his blood from France or from Russia, from
America or from England, each one of which owes Ireland a
measureless debt. And all who love truth in history and gratitude for
priceless gifts received, will urge your Society onward every day and
hour you labor in the work you have so well begun till every heroic
son of this great line who has helped to build the fabric of American
liberty shall have his rightful place in history and the laurels he has
fairly won.
“I have now come to that which, in justice to Major General John
Sullivan, I think should be related. I shall ask you to turn from the
beautiful State in which you live to that far off region of beauty in
which I have the honor to hold my home. In 1778 occurred in
Wyoming that awful massacre whose horrors yet ring in the history
of our country and in the hearts of the descendants of those who lost
part of their families, who lost limb, who lost health, who were
maimed, in that most horrible of savage invasions. Early in 1779
Congress, representing a country which had been shocked to the
limit by those terrible outrages, passed a resolution of unlimited
vigor, calling upon Washington to arrange for their punishment. It
was suggested at first to Washington that General Gates should have
the command, but Washington, whose knowledge of Indian warfare
was complete, wanted General Sullivan, and to that officer was
entrusted the conduct of that great fight.
“In the history of Indian warfare in this country there is nothing
more successful, more thoroughly creditable to the commanding
officer, than the history of what General John Sullivan and his
command did in the then wilderness reaching from Wyoming to the
Genesee; and today, think of him what you may, build to him tablets
as beautiful as this, recall his manifestly skilful work in the State
where you stand, and you cannot accord to him one half the
veneration and the love which the citizens of the counties around me,
now a million in number, feel towards General John Sullivan for the
work which opened up that magnificent line of valleys unequalled in
their fertility, and whose line of bordering hills to this day, one
hundred and thirty years after, is resounding with thanksgiving and
praise for what General John Sullivan did there.
“Every morning when I look out of my window in the far distance I
can see in the battlefield which decided the ownership of that region
a tall and stately monument built by private subscription to General
Sullivan, to commemorate his work on that bloody day, and just
below it stands a magnificent marker of granite, placed there by the
Sons of the American Revolution to mark the very center of the
conflict which took those valleys away from the possession of the
Indians and turned them over to civilization and happy and peaceful
occupation; and those who know the iron will and determined
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

You might also like