Skip to content

Commit 51d12f2

Browse files
committed
Replace 'class' with 'typename' in template parameters
1 parent b1bff91 commit 51d12f2

File tree

9 files changed

+26
-26
lines changed

9 files changed

+26
-26
lines changed

src/content/1.1/category-the-essence-of-composition.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ \section{Properties of Composition}
131131
universally polymorphic. In C++ we could define it as a template:
132132

133133
\begin{snip}{cpp}
134-
template<class T> T id(T x) { return x; }
134+
template<typename T> T id(T x) { return x; }
135135
\end{snip}
136136
Of course, in C++ nothing is that simple, because you have to take into
137137
account not only what you're passing but also how (that is, by value, by

src/content/1.10/natural-transformations.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ \section{Polymorphic Functions}
162162
syntax. A similar construct in C++ would be slightly more verbose:
163163

164164
\begin{snip}{cpp}
165-
template<class A> G<A> alpha(F<A>);
165+
template<typename A> G<A> alpha(F<A>);
166166
\end{snip}
167167
There is a more profound difference between Haskell's polymorphic
168168
functions and C++ generic functions, and it's reflected in the way these

src/content/1.2/types-and-functions.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ \section{Examples of Types}
394394
In C++ you would write this function as:
395395

396396
\begin{snip}{cpp}
397-
template<class T>
397+
template<typename T>
398398
void unit(T) {}
399399
\end{snip}
400400
Next in the typology of types is a two-element set. In C++ it's called

src/content/1.3/categories-great-and-small.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ \section{Monoid as Set}
180180
C++20 standard's concept feature.
181181

182182
\begin{snip}{cpp}
183-
template<class T>
183+
template<typename T>
184184
struct mempty;
185185

186-
template<class T>
186+
template<typename T>
187187
T mappend(T, T) = delete;
188188

189-
template<class M>
189+
template<typename M>
190190
concept Monoid = requires (M m) {
191191
{ mempty<M>::value() } -> std::same_as<M>;
192192
{ mappend(m, m) } -> std::same_as<M>;

src/content/1.4/kleisli-categories.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
\code{A} and the second component is a string:
121121

122122
\begin{snip}{cpp}
123-
template<class A>
123+
template<typename A>
124124
using Writer = pair<A, string>;
125125
\end{snip}
126126
Here are the embellished functions:
@@ -226,7 +226,7 @@ \section{The Writer Category}
226226
return a third embellished function:
227227

228228
\begin{snip}{cpp}
229-
template<class A, class B, class C>
229+
template<typename A, typename B, typename C>
230230
function<Writer<C>(A)> compose(function<Writer<B>(A)> m1,
231231
function<Writer<C>(B)> m2)
232232
{
@@ -282,7 +282,7 @@ \section{The Writer Category}
282282
string to the log:
283283

284284
\begin{snip}{cpp}
285-
template<class A>
285+
template<typename A>
286286
Writer<A> identity(A x) {
287287
return make_pair(x, "");
288288
}
@@ -411,7 +411,7 @@ \section{Challenge}
411411
type \code{optional}:
412412

413413
\begin{snip}{cpp}
414-
template<class A>
414+
template<typename A>
415415
class optional {
416416
bool _isValid;
417417
A _value;

src/content/1.5/products-and-coproducts.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ \section{Products}
244244
In C++, we would use template functions, for instance:
245245

246246
\begin{snip}{cpp}
247-
template<class A, class B>
247+
template<typename A, typename B>
248248
A fst(pair<A, B> const & p) {
249249
return p.first;
250250
}

src/content/1.6/simple-algebraic-data-types.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ \section{Sum Types}
253253
empty list:
254254

255255
\begin{snip}{cpp}
256-
template<class A>
256+
template<typename A>
257257
class List {
258258
Node<A> * _head;
259259
public:

src/content/1.7/functors.tex

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ \subsection{Optional}
266266
management issues characteristic of C++):
267267

268268
\begin{snip}{cpp}
269-
template<class T>
269+
template<typename T>
270270
class optional {
271271
bool _isValid; // the tag
272272
T _v;
@@ -282,7 +282,7 @@ \subsection{Optional}
282282
functions:
283283

284284
\begin{snip}{cpp}
285-
template<class A, class B>
285+
template<typename A, typename B>
286286
std::function<optional<B>(optional<A>)>
287287
fmap(std::function<B(A)> f) {
288288
return [f](optional<A> opt) {
@@ -297,7 +297,7 @@ \subsection{Optional}
297297
returning a function. Here's the uncurried version of it:
298298

299299
\begin{snip}{cpp}
300-
template<class A, class B>
300+
template<typename A, typename B>
301301
optional<B> fmap(std::function<B(A)> f, optional<A> opt) {
302302
if (!opt.isValid())
303303
return optional<B>{};
@@ -380,22 +380,22 @@ \subsection{Functor in C++}
380380
\code{F}. This is the syntax for it:
381381

382382
\begin{snip}{cpp}
383-
template<template<class> F, class A, class B>
383+
template<template<typename> F, typename A, typename B>
384384
F<B> fmap(std::function<B(A)>, F<A>);
385385
\end{snip}
386386
We would like to be able to specialize this template for different
387387
functors. Unfortunately, there is a prohibition against partial
388388
specialization of template functions in C++. You can't write:
389389

390390
\begin{snip}{cpp}
391-
template<class A, class B>
391+
template<typename A, typename B>
392392
optional<B> fmap<optional>(std::function<B(A)> f, optional<A> opt)
393393
\end{snip}
394394
Instead, we have to fall back on function overloading, which brings us
395395
back to the original definition of the uncurried \code{fmap}:
396396

397397
\begin{snip}{cpp}
398-
template<class A, class B>
398+
template<typename A, typename B>
399399
optional<B> fmap(std::function<B(A)> f, optional<A> opt) {
400400
if (!opt.isValid())
401401
return optional<B>{};
@@ -456,7 +456,7 @@ \subsection{The List Functor}
456456
is just a thin encapsulation of \code{std::transform}:
457457

458458
\begin{snip}{cpp}
459-
template<class A, class B>
459+
template<typename A, typename B>
460460
std::vector<B> fmap(std::function<B(A)> f, std::vector<A> v) {
461461
std::vector<B> w;
462462
std::transform( std::begin(v)
@@ -611,7 +611,7 @@ \section{Functors as Containers}
611611
arguments --- which are compile-time --- and values, which are run-time:
612612

613613
\begin{snip}{cpp}
614-
template<class C, class A>
614+
template<typename C, typename A>
615615
struct Const {
616616
Const(C v) : _v(v) {}
617617
C _v;
@@ -622,7 +622,7 @@ \section{Functors as Containers}
622622
changing its value:
623623

624624
\begin{snip}{cpp}
625-
template<class C, class A, class B>
625+
template<typename C, typename A, typename B>
626626
Const<C, B> fmap(std::function<B(A)> f, Const<C, A> c) {
627627
return Const<C, B>{c._v};
628628
}

src/content/1.8/functoriality.tex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,15 @@ \section{Functors in C++}
305305
a good idea in any case):
306306

307307
\begin{snip}{cpp}
308-
template<class T>
309-
struct Tree {
308+
template<typename T>
309+
struct Tree {
310310
virtual ~Tree() {}
311311
};
312312
\end{snip}
313313
The \code{Leaf} is just an \code{Identity} functor in disguise:
314314

315315
\begin{snip}{cpp}
316-
template<class T>
316+
template<typename T>
317317
struct Leaf : public Tree<T> {
318318
T _label;
319319
Leaf(T l) : _label(l) {}
@@ -322,7 +322,7 @@ \section{Functors in C++}
322322
The \code{Node} is a product type:
323323

324324
\begin{snip}{cpp}
325-
template<class T>
325+
template<typename T>
326326
struct Node : public Tree<T> {
327327
Tree<T> * _left;
328328
Tree<T> * _right;
@@ -338,7 +338,7 @@ \section{Functors in C++}
338338
thinking.
339339

340340
\begin{snip}{cpp}
341-
template<class A, class B>
341+
template<typename A, typename B>
342342
Tree<B> * fmap(std::function<B(A)> f, Tree<A> * t) {
343343
Leaf<A> * pl = dynamic_cast <Leaf<A>*>(t);
344344
if (pl)

0 commit comments

Comments
 (0)