Skip to content

Commit 2e76f4b

Browse files
Reason edition: tex files, makefile, logo & colors.
1 parent cc68671 commit 2e76f4b

File tree

13 files changed

+327
-6
lines changed

13 files changed

+327
-6
lines changed

src/Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Igal Tabachnik, 2007.
22
# Based on work by Andres Raba et al., 2013-2015.
33

4-
.PHONY: default all clean out-dir version.tex scala ocaml
4+
.PHONY: default all clean out-dir version.tex scala ocaml reason
55

66
DIR := $(shell pwd)
77
GIT_VER := $(shell git describe --tags --always --long | tr -d '\n')
@@ -15,8 +15,10 @@ SCALATEXFILES = ctfp-reader-scala.tex ctfp-print-scala.tex # todo make this a ma
1515

1616
OCAMLTEXFILES = ctfp-reader-ocaml.tex ctfp-print-ocaml.tex # todo make this a macro
1717

18+
REASONTEXFILES = ctfp-reader-reason.tex ctfp-print-reason.tex # todo make this a macro
19+
1820
# Top-level LaTeX files from which CTFP book can be generated
19-
TOPTEXFILES = version.tex $(DEFAULTTOPTEX) $(SCALATEXFILES) $(OCAMLTEXFILES)
21+
TOPTEXFILES = version.tex $(DEFAULTTOPTEX) $(SCALATEXFILES) $(OCAMLTEXFILES) $(REASONTEXFILES)
2022

2123
# Default PDF file to make
2224
DEFAULTPDF:=$(DEFAULTTOPTEX:.tex=.pdf)
@@ -27,6 +29,9 @@ SCALAPDF:=$(SCALATEXFILES:.tex=.pdf)
2729
# OCaml PDF file to make
2830
OCAMLPDF:=$(OCAMLTEXFILES:.tex=.pdf)
2931

32+
# ReasonML PDF file to make
33+
REASONPDF:=$(REASONTEXFILES:.tex=.pdf)
34+
3035
# Other PDF files for the CTFP book
3136
TOPPDFFILES:=$(TOPTEXFILES:.tex=.pdf)
3237

@@ -36,7 +41,7 @@ OPTFILES = opt-print-ustrade.tex \
3641
opt-scala.tex
3742

3843
# All the LaTeX files for the CTFP book in order of dependency
39-
TEXFILES = $(TOPTEXFILES) $(SCALATEXFILES) $(OCAMLTEXFILES) $(OPTFILES)
44+
TEXFILES = $(TOPTEXFILES) $(SCALATEXFILES) $(OCAMLTEXFILES) $(REASONTEXFILES) $(OPTFILES)
4045

4146
default: suffix=''
4247
default: out-dir $(DEFAULTPDF) # todo cover
@@ -49,6 +54,9 @@ scala: clean out-dir version.tex $(SCALAPDF)
4954
ocaml: suffix='-ocaml'
5055
ocaml: clean out-dir version.tex $(OCAMLPDF)
5156

57+
reason: suffix='-reason'
58+
reason: out-dir version.tex $(REASONPDF)
59+
5260
# Main targets
5361
$(TOPPDFFILES) : %.pdf : %.tex $(TEXFILES)
5462
if which latexmk > /dev/null 2>&1 ;\
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/* ReasonML/OCaml only allows special characters in the infix operator. So, the above function name cannot be applied as infix. */
1+
// ReasonML/OCaml only allows special characters in the infix operator.
2+
// So, the above function name cannot be applied as infix.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* Gen.t is used to represent infinite data structures like haskell's lazy list */
2-
external unfold: ('b => option(('a, 'b)), 'b) => Gen.t('a) = ;
2+
let unfold: ('b => option(('a, 'b)), 'b) => Gen.t('a);

src/content/reason/colophon.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ReasonML code translation was done by \urlref{https://github.com/fhammerschmidt/}{Florian Hammerschmidt}.

src/content/reason/editor-note.tex

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
% !TEX root = ctfp-print.tex
2+
3+
\lettrine[lhang=0.17]{T}{his is the} ReasonML edition of \emph{Category Theory for Programmers}.
4+
It's been a tremendous success, making Bartosz Milewski's blog post series available as a nicely-
5+
typeset \acronym{PDF}, as well as a hardcover book. There have been numerous contributions made
6+
to improve the book, by fixing typos and errors, as well as translating the code snippets into
7+
other programming languages.
8+
9+
I am thrilled to present this edition of the book, containing the original Haskell code, followed by
10+
its ReasonML counterpart. The ReasonML code snippets were converted from the OCaml snippets which were
11+
generously provided by \urlref{https://github.com/ArulselvanMadhavan/ocaml-ctfp}{ocaml-ctfp} contributors,
12+
and slightly modified to suit the format of this book.
13+
14+
To support code snippets in multiple languages, I am using a \LaTeX{} macro to load the code snippets
15+
from external files. This allows easily extending the book with other languages, while leaving the
16+
original text intact. Which is why you should mentally append the words ``and ReasonML'' whenever you see
17+
``in Haskell'' in the text.
18+
19+
The code is laid out in the following manner: the original Haskell code, followed by ReasonML code.
20+
To distinguish between them, the code snippets are braced from the left with a vertical bar, in the primary
21+
color of the language's logo, \raisebox{-.2mm}{\includegraphics[height=.3cm]{fig/icons/haskell.png}},
22+
and \raisebox{-.2mm}{\includegraphics[height=.3cm]{fig/icons/reason.png}} respectively, e.g.:
23+
24+
\srcsnippet{content/1.1/code/haskell/snippet03.hs}{blue}{haskell}
25+
\unskip
26+
\srcsnippet{content/1.1/code/reason/snippet03.re}{RedOrange}{reason}
27+
\NoIndentAfterThis
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
\documentclass[
2+
coverheight=9.249in,
3+
coverwidth=6.319in, % (pagesize - spinewidth) / 2
4+
spinewidth=1.125in,
5+
bleedwidth=0.306in,
6+
11pt,
7+
marklength=0pt,
8+
]{bookcover}
9+
10+
\usepackage{fancybox}
11+
\usepackage{wrapfig}
12+
\usepackage[many]{tcolorbox}
13+
\usetikzlibrary{calc,positioning, shadings}
14+
\usepackage[T1]{fontenc}
15+
\usepackage{fontspec}
16+
17+
\setmainfont[
18+
Path=fonts/,
19+
Extension=.otf,
20+
UprightFont=*-Regular,
21+
ItalicFont=*-Italic,
22+
BoldFont=*-Bold,
23+
UprightFeatures={SmallCapsFont=*SC-Regular},
24+
ItalicFeatures={SmallCapsFont=*SC-Italic},
25+
BoldFeatures={SmallCapsFont=*SC-Bold},
26+
BoldItalicFeatures={SmallCapsFont=*SC-BoldItalic},
27+
]{AlegreyaSans}
28+
29+
\newcommand{\olpath}{../}
30+
\newcommand{\whitebg}[1]{%
31+
\tikz\node[circle,draw,minimum size=1.1cm,
32+
fill=white,
33+
path picture={
34+
\node at (path picture bounding box){
35+
\includegraphics[width=1.1cm]{\olpath#1}
36+
};
37+
}]{};
38+
}
39+
\newcommand{\bartosz}{
40+
\vspace{0pt}
41+
\begin{tcolorbox}[beamer,
42+
width=3.6cm,
43+
arc=0pt,
44+
boxsep=0pt,
45+
left=0pt,right=0pt,top=0pt,bottom=0pt,
46+
] \includegraphics[width=3.6cm]{bartosz}
47+
\end{tcolorbox}
48+
}
49+
\input{\olpath/version}
50+
51+
\definecolor{BackgroundColor}{HTML}{f3f6ed}
52+
\definecolor{SpineBackColor}{HTML}{262626}
53+
54+
\begin{document}
55+
56+
\begin{bookcover}
57+
\bookcovercomponent{color}{bg whole}{color=BackgroundColor}
58+
\bookcovercomponent{color}{spine}{color=SpineBackColor}
59+
\bookcovercomponent{normal}{front}{
60+
\input{ribbon-reason}
61+
\vspace{1.1cm}
62+
\begin{center}
63+
\fontsize{40pt}{5em}\selectfont\bfseries
64+
CATEGORY THEORY \\FOR PROGRAMMERS
65+
\vfil
66+
\hspace*{-.8cm}\includegraphics[width=.5\coverwidth]{piggie}
67+
\linebreak
68+
\rule[1.5cm]{\textwidth/2}{.5pt}\\
69+
\vspace{-1.5cm}
70+
\normalfont\Huge\textbf{Bartosz Milewski}
71+
\vfil
72+
\vspace*{1cm}
73+
\end{center}}
74+
75+
\bookcovercomponent{center}{spine}{
76+
\rotatebox[origin=c]{-90}{\color{orange}
77+
\Huge\bfseries Category Theory for Programmers \hspace{2em} Bartosz Milewski}}
78+
79+
\bookcovercomponent{normal}{back}{%
80+
\begin{minipage}[b][\coverheight][t]{\coverwidth}
81+
\begin{center}
82+
\vspace{1cm}
83+
\includegraphics[width=.8\coverwidth]{bunnies}
84+
\begin{minipage}[t]{.8\coverwidth}
85+
\input{blurb}
86+
\vspace{.5cm}
87+
\end{minipage}
88+
89+
\begin{minipage}{.85\textwidth}
90+
\rule{\textwidth}{.5pt}
91+
92+
\begin{tabular}[h]{p{3.4cm} p{\textwidth}}
93+
\bartosz
94+
&
95+
\vspace{5pt}
96+
\begin{minipage}[b]{.58\coverwidth}
97+
\fontsize{11pt}{1.4em}\selectfont\textit{Category Theory for Programmers}
98+
is a series of blog posts by Bartosz Milewski, originally posted on bartoszmilewski.com.\\
99+
Edited by Igal Tabachnik. Licenced under CC BY-SA 4.0.\\
100+
\end{minipage}
101+
\end{tabular}
102+
\begin{flushright}
103+
\vspace{-2.6cm}
104+
\begin{minipage}[b]{4cm}
105+
\raggedleft
106+
\whitebg{fig/icons/by}
107+
\whitebg{fig/icons/cc}
108+
\whitebg{fig/icons/sa}
109+
\centering\footnotesize{\texttt{\OPTversion}}
110+
\end{minipage}
111+
\end{flushright}
112+
\end{minipage}
113+
\end{center}
114+
\end{minipage}
115+
}
116+
\end{bookcover}
117+
\end{document}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
\documentclass[
2+
% bleed is added to the final result
3+
coverheight=9.25in,
4+
coverwidth=6.125in, % (pagesize - spinewidth) / 2 == (13.042 - 1.042) / 2
5+
spinewidth=1.042in,
6+
bleedwidth=0in,
7+
11pt,
8+
marklength=0in,
9+
]{bookcover}
10+
11+
\usepackage{fancybox}
12+
\usepackage{wrapfig}
13+
\usepackage[many]{tcolorbox}
14+
\usetikzlibrary{calc,positioning, shadings}
15+
\usepackage[T1]{fontenc}
16+
\usepackage{fontspec}
17+
18+
% \setmainfont{AlegreyaSans-Regular}[
19+
% BoldFont={AlegreyaSans-Bold},
20+
% ItalicFont={AlegreyaSans-Italic},
21+
% UprightFeatures={SmallCapsFont=AlegreyaSansSC-Regular},
22+
% ItalicFeatures={SmallCapsFont=AlegreyaSansSC-Italic},
23+
% BoldFeatures={SmallCapsFont=AlegreyaSansSC-Bold},
24+
% BoldItalicFeatures={SmallCapsFont=AlegreyaSansSC-BoldItalic},
25+
% ]
26+
\setmainfont[
27+
Path=fonts/,
28+
Extension=.otf,
29+
UprightFont=*-Regular,
30+
ItalicFont=*-Italic,
31+
BoldFont=*-Bold,
32+
UprightFeatures={SmallCapsFont=*SC-Regular},
33+
ItalicFeatures={SmallCapsFont=*SC-Italic},
34+
BoldFeatures={SmallCapsFont=*SC-Bold},
35+
BoldItalicFeatures={SmallCapsFont=*SC-BoldItalic},
36+
]{AlegreyaSans}
37+
38+
\newcommand{\olpath}{../}
39+
\newcommand{\whitebg}[1]{%
40+
\tikz\node[circle,draw,minimum size=1.1cm,
41+
fill=white,
42+
path picture={
43+
\node at (path picture bounding box){
44+
\includegraphics[width=1.1cm]{\olpath#1}
45+
};
46+
}]{};
47+
}
48+
\newcommand{\bartosz}{
49+
\vspace{0pt}
50+
\begin{tcolorbox}[beamer,
51+
width=3.6cm,
52+
arc=0pt,
53+
boxsep=0pt,
54+
left=0pt,right=0pt,top=0pt,bottom=0pt,
55+
] \includegraphics[width=3.6cm]{bartosz}
56+
\end{tcolorbox}
57+
}
58+
\input{\olpath/version}
59+
60+
\definecolor{BackgroundColor}{HTML}{f3f6ed}
61+
\definecolor{SpineBackColor}{HTML}{262626}
62+
63+
\begin{document}
64+
65+
\begin{bookcover}
66+
\bookcovercomponent{color}{bg whole}{color=BackgroundColor}
67+
\bookcovercomponent{color}{spine}{color=SpineBackColor}
68+
\bookcovercomponent{normal}{front}{
69+
\input{ribbon-reason}
70+
\vspace{1.1cm}
71+
\begin{center}
72+
\fontsize{40pt}{5em}\selectfont\bfseries
73+
CATEGORY THEORY \\FOR PROGRAMMERS
74+
\vfil
75+
\hspace*{-.8cm}\includegraphics[width=.5\coverwidth]{piggie}
76+
\linebreak
77+
\rule[1.5cm]{\textwidth/2}{.5pt}\\
78+
\vspace{-1.5cm}
79+
\normalfont\Huge\textbf{Bartosz Milewski}
80+
\vfil
81+
\vspace*{1cm}
82+
\end{center}}
83+
84+
\bookcovercomponent{center}{spine}{
85+
\rotatebox[origin=c]{-90}{\color{orange}
86+
\Huge\bfseries Category Theory for Programmers \hspace{2em} Bartosz Milewski}}
87+
88+
\bookcovercomponent{normal}{back}{%
89+
\begin{minipage}[b][\coverheight][t]{\coverwidth}
90+
\begin{center}
91+
\vspace{1cm}
92+
\includegraphics[width=.8\coverwidth]{bunnies}
93+
\begin{minipage}[t]{.75\coverwidth}
94+
\input{blurb}
95+
\vspace{0.6cm}
96+
\end{minipage}
97+
98+
\begin{minipage}{.85\textwidth}
99+
\rule{\textwidth}{.5pt}
100+
101+
\begin{tabular}[h]{p{3.4cm} p{\textwidth}}
102+
\vspace{5pt}
103+
\bartosz
104+
&
105+
\vspace{10pt}
106+
\begin{minipage}[b]{.58\coverwidth}
107+
\fontsize{11pt}{1.4em}\selectfont\textit{Category Theory for Programmers}
108+
is a series of blog posts by Bartosz Milewski, originally posted on bartoszmilewski.com.\\
109+
Edited by Igal Tabachnik. Licenced under CC BY-SA 4.0.\\
110+
\end{minipage}
111+
\end{tabular}
112+
\begin{flushright}
113+
\vspace{-2.6cm}
114+
\begin{minipage}[b]{4cm}
115+
\raggedleft
116+
\whitebg{fig/icons/by}
117+
\whitebg{fig/icons/cc}
118+
\whitebg{fig/icons/sa}
119+
\centering\footnotesize{\texttt{\OPTversion}}
120+
\end{minipage}
121+
\end{flushright}
122+
\end{minipage}
123+
\end{center}
124+
\end{minipage}
125+
}
126+
\end{bookcover}
127+
\end{document}

src/cover/ribbon-ocaml.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
\coordinate (B) at ($ (current page.south east) + (0,\stripskip) $);% <-- changed coordinate from 'north' to south' and sign for \stripskip
1818
\coordinate (B') at ($(B) + (0,\stripwidth) $);% <-- changed sign for \stripskip
1919

20-
\fill [BurntOrange!20] (A) -- (A') -- (B') -- (B) -- cycle;
20+
\fill [RedOrange!20] (A) -- (A') -- (B') -- (B) -- cycle;
2121

2222
\coordinate (tempA) at ($(A)!.5!(A')$);
2323
\coordinate (tempB) at ($(B)!.5!(B')$);

src/cover/ribbon-reason.tex

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
% !TeX root = ./cover-paperback-reason.tex
2+
3+
\newcommand{\stripskip}{4}
4+
\newcommand{\stripwidth}{3}
5+
6+
\definecolor{RedOrange}{rgb}{0.8, 0.33, 0.0}
7+
8+
\begin{tikzpicture}[
9+
overlay,
10+
remember picture,
11+
ribbon/.style={anchor=center, rotate = 45,
12+
font={\fontsize{22}{1}\selectfont\bfseries}}
13+
]
14+
\coordinate (A) at ($ (current page.south east) + (-\stripskip,0) $);% <-- changed coordinate from 'north' to south'
15+
\coordinate (A') at ($(A) + (-\stripwidth,0) $);
16+
17+
\coordinate (B) at ($ (current page.south east) + (0,\stripskip) $);% <-- changed coordinate from 'north' to south' and sign for \stripskip
18+
\coordinate (B') at ($(B) + (0,\stripwidth) $);% <-- changed sign for \stripskip
19+
20+
\fill [RedOrange!20] (A) -- (A') -- (B') -- (B) -- cycle;
21+
22+
\coordinate (tempA) at ($(A)!.5!(A')$);
23+
\coordinate (tempB) at ($(B)!.5!(B')$);
24+
25+
\node [ribbon](text) at ($(tempA)!.5!(tempB)$) {
26+
\raisebox{-.15\height}{\includegraphics[width=.8cm]{\olpath/fig/icons/reason}}
27+
\hspace{.5mm} ReasonML Edition
28+
};
29+
30+
\end{tikzpicture}

src/ctfp-print-reason.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\input{opt-reason}
2+
\input{ctfp-print}
3+
\input{postamble}

0 commit comments

Comments
 (0)