This repository has been archived by the owner on Nov 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcs141.tex
276 lines (222 loc) · 8.42 KB
/
cs141.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LaTeX sources for The Guide to Functional Programming
%% Michael B. Gale ([email protected])
%%
%% This work is licensed under the Creative Commons
%% Attribution-NonCommercial-NoDerivatives 4.0 International License. To
%% view a copy of this license, visit
%% http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to
%% Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[12pt,a4paper,twoside,fleqn]{report}
\usepackage{geometry}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{fancyeq}
\usepackage{fancyhdr}
\usepackage[explicit]{titlesec}
\usepackage{color}
\usepackage{longtable}
\usepackage{array, booktabs}
\usepackage{colortbl}
\usepackage{wrapfig}
\usepackage{pgfplots}
\usepackage[strict]{changepage}
\usepackage{graphbox}
\usepackage{prerex}
\usepackage{forest}
\usepackage{multicol}
\usepackage{fontawesome}
\usepackage{natbib}
\usepackage{ccicons}
% Minted -------------------------------
\usepackage{minted}
\usepackage[
backgroundcolor = gray!5
, hidealllines=true
]{mdframed}
\surroundwithmdframed{minted}
\usemintedstyle{lovelace}
\setminted[text]{fontsize=\small}
\setminted[haskell]{fontsize=\small}
\setminted[bash]{fontsize=\small}
\newcommand{\haskellIn}[1]{\mintinline[fontsize=\small]{haskell}{#1}}
\newcommand{\bashIn}[1]{\mintinline[fontsize=\small]{bash}{#1}}
% Tikz -------------------------------
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{
treenode/.style = {align=center, inner sep=0pt, text centered,
font=\sffamily},
arn_n/.style = {treenode, circle, white, font=\sffamily\bfseries, draw=black,
fill=black, text width=1.5em},
arn_r/.style = {treenode, circle, red, draw=red,
text width=1.5em, very thick},
arn_x/.style = {treenode, circle, draw=white,
minimum width=1.5em, minimum height=1.5em},
cls/.style = { treenode, rectangle, red, draw=red,
text width=1.5em, very thick, minimum width=1.5em, minimum height=1.5em }
}
% UK English -------------------------------
\usepackage[UKenglish]{babel}
\usepackage[UKenglish]{isodate}
% Hyperref -------------------------------
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=black,
urlcolor=black,
citecolor=black,
unicode=false
}
% cleveref
\usepackage[nameinlink]{cleveref}
\crefname{figure}{figure}{figures} % cleveref by default has `fig.'
\Crefname{figure}{Figure}{Figures}
\crefname{section}{section}{sections} % cleveref by default has `fig.'
\Crefname{section}{Section}{Sections}
% Fonts -------------------------------
\usepackage[]{FiraSans}
% Palatino (font)
\usepackage{mathpazo}
\linespread{1.05} % Palatino needs more leading (space between lines)
\usepackage[T1]{fontenc}
% some format settings
% for hard-bound final submission, use:
%\setlength{\oddsidemargin}{4.6mm} % 30 mm left margin - 1 in
% for soft-bound version and techreport, use instead:
\setlength{\oddsidemargin}{-0.4mm} % 25 mm left margin - 1 in
\setlength{\evensidemargin}{-0.4mm}
\setlength{\topmargin}{-5.4mm} % 20 mm top margin - 1 in
\setlength{\textwidth}{160mm} % 20/25 mm right margin
\setlength{\textheight}{237mm} % 20 mm bottom margin
\setlength{\headheight}{5mm}
\setlength{\headsep}{5mm}
\setlength{\parindent}{0mm}
\setlength{\parskip}{\medskipamount}
\renewcommand\baselinestretch{1.2} % thesis format (not needed for techreport)
% don't let large figures hijack entire pages
\renewcommand\topfraction{.9}
\renewcommand\textfraction{.1}
\renewcommand\floatpagefraction{.8}
\usepackage[nomap]{FiraMono}
\usepackage{microtype}
\DisableLigatures[f]{encoding = *, family = tt* }
\author{Michael B. Gale}
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}
\titleformat{name=\chapter}[hang]{}{}{0cm}{%
\protect\thispagestyle{fancy}
\begin{center}
\large $\lambda$.\thechapter \\
\huge \textsc{#1}
\end{center}
%\chaptermark{\chapter}
}
\titleformat{name=\chapter,numberless}[hang]{}{}{0cm}{%
\begin{center}
\huge \textsc{#1}
\end{center}
%\chaptermark{\chapter}
}
%\titleformat{\subsection}{format}{label}{0em}{before-code}
\titleformat{\section}
{\bfseries\large}
{\llap{\parbox{1.5cm}{\thesection\hfill}}#1}
{0em}
{\bfseries}
\titleformat{\subsection}
{\bfseries}{\llap{\parbox{1.5cm}{\thesubsection\hfill}}#1}{0em}{\bfseries}
% misc. commands
\newcounter{TaskCounter}
\newcommand{\question}[1]{\vspace{-0.7cm}{\footnotesize \emph{#1}} \vspace{0.25cm}}
\newcommand{\topics}[1]{\vspace{-0.5cm}{\footnotesize \emph{Topics}: #1} \vspace{0.25cm}}
\newcommand{\task}[2][]{\indent\llap{\parbox{1.5cm}{\refstepcounter{TaskCounter}\label{#1}{\firamedium Ex\theTaskCounter}\hfill}}#2}
\newcommand{\solution}[2]{\indent\llap{\parbox{1.5cm}{\textbf{Ex#1}\hfill}}#2}
\newcommand{\taskLine}{\bigskip\hrule\bigskip}
% titles, dates, etc. of lectures and labs
\input{topics.tex}
\AtBeginDocument{\addtocontents{toc}{\protect\thispagestyle{fancy}}}
\begin{document}
\fancypagestyle{empty}{\fancyhf{}}
\pagestyle{empty}
\pagenumbering{roman}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\input{titlepage.tex}
\cleardoublepage
%\setcounter{page}{1}
\fancyhf{}
\fancyhead[LE, RO]{\emph{The Guide to Functional Programming}}
\fancyhead[LO, RE]{\emph{Michael B. Gale}}
%\fancyhead[RE,LO]{Guides and tutorials}
%\fancyfoot[CE,CO]{\leftmark}
\fancyfoot[LE,RO]{\thepage}
\pagestyle{fancy}
\thispagestyle{fancy}
\newgeometry{
tmargin=2.5cm,
textwidth=155mm,
textheight=247mm,
headheight=5mm,
headsep=5mm,
inner=30mm
}
\tableofcontents
\cleardoublepage
\pagenumbering{arabic}
\input{overview.tex}
\input{books.tex}
\input{timeline.tex}
\input{coursework.tex}
\input{exam.tex}
\input{guidance.tex}
\input{lecture-notes.tex}
\cleardoublepage
\chapter{Exercises}
This chapter contains exercises for the module. Each section in this chapter corresponds to one topic from the lectures. You can find recommendations for which sets of exercises to complete after a given lecture on the module website and recommendations for each week of term in \Cref{sec:timeline}. We strongly recommend that you try to keep up with the exercises as they are very valuable for the coursework. If you are not following the order in which the exercises are presented in this guide, the graph below shows prerequisite dependencies between topics in the module:
\input{labs/dependencies.tex}
CS141 lab sessions should primarily be fun! Make use of them to practice the skills we cover in the lectures and to ask us questions. We do take a register to keep track of attendance, but if you should miss a lab \emph{e.g.} due to illness, that's not an issue and you are welcome to attend an online lab at a later time instead.
\input{labs/lab-getting-started.tex} \newpage
\input{labs/lab-functions.tex} \newpage
\input{labs/lab-basic-types.tex} \newpage
\input{labs/lab-prelude.tex} \newpage
\input{labs/lab-lists.tex} \newpage
\input{labs/lab-type-classes.tex} \newpage
\input{labs/lab-list-comprehensions.tex} \newpage
\input{labs/lab-recursive-functions.tex} \newpage
\input{labs/lab-higher-order-functions.tex} \newpage
\input{labs/lab-dependencies.tex} \newpage
\input{labs/lab-data-types.tex} \newpage
\input{labs/lab-recursive-types.tex} \newpage
\input{labs/lab-lazy-evaluation.tex} \newpage
\input{labs/lab-equational-reasoning.tex} \newpage
\input{labs/lab-foldable.tex} \newpage
\input{labs/lab-functors.tex} \newpage
\input{labs/lab-applicatives.tex} \newpage
\input{labs/lab-effectful-programming.tex} \newpage
\input{labs/lab-io.tex} \newpage
\input{labs/lab-kinds.tex} \newpage
\input{labs/lab-tlp.tex}
\input{cswk/lac.tex}
\input{cswk/scratch-clone.tex}
\input{cswk/revision-projects.tex}
\cleardoublepage
\chapter{Solutions}
This section contains model answers for selected exercises along with descriptions of how they could be derived. You should only read these for revision purposes or once you have completed the exercises yourself. Remember that it is better for you to ask for help in figuring something out than to just jump to the solutions.
\input{labs/sol-recursive-functions.tex}
\input{labs/sol-equational-reasoning.tex}
\input{labs/sol-functors.tex}
\input{prelude.tex}
\pagestyle{fancy}
\thispagestyle{fancy}
\phantomsection
\addcontentsline{toc}{chapter}{Bibliography}
\bibliographystyle{kbib}
\bibliography{cs141}
\pagestyle{fancy}
\thispagestyle{fancy}
\end{document}