Skip to content

Commit

Permalink
Continue working on chapter 13 (#69)
Browse files Browse the repository at this point in the history
* wip

* fix formatting

* wip

* correction from Andreas

* wip

* wip

* more exercises for traversables

* wip zipWithIndex lemma

* wip

* wip

* wip

* wip proof of zipwithindex properties

* wip

* minor updates

* wip

* wip

* wip traversable properties

* wip

* wip

* wip

* wip

* fix text of exercise 2.1.7.8

* wip

* wip

* reformatting to 12pt

* copy lyx header

* reformat chapter 1 again

* build tex

* wip

* wip

* add exercise for non-standard zip

* wip

* reformat chapter 2 wip

* wip reformat chapter 2

* wip chapter 2

* wip

* finish reformatting ch.2

* wip

* wip

* edit chapters 1-5

* minor fixes

* create scripts for volumes 1-3

* vol1 is ready

* 3 volumes without hyperlinks or covers

* wip

* wip

* rename "solved examples" to "examples"

* implement barcode and set all margins

* add two isbns for vols. 1,2 so far

* fix formatting of barcode

* remove wrap floats from chapters 6 and 7

* wip remove wrap floats from chapters 6 and 8

* wip

* responding to PR by Andreas

* responding to Andreas

* wip reformatting part 2

* remove float wraps from part 2

* prepare a 10pt pdf file

* minor corrections

---------

Co-authored-by: sergei.winitzki <sergei.winitzki@workday.com>
  • Loading branch information
winitzki and sergei.winitzki committed Jan 22, 2024
1 parent 45aeabf commit 52a14a2
Show file tree
Hide file tree
Showing 61 changed files with 30,786 additions and 36,004 deletions.
32 changes: 28 additions & 4 deletions .github/workflows/build-pdf.yml
Expand Up @@ -39,7 +39,7 @@ jobs:
name: PDF files and LaTeX logs
path: |
./sofp-src/sofp*.pdf
./sofp-src/book_cover/sofp-3page-cover.pdf
./sofp-src/sofp*-3page-cover.pdf
./sofp-src/sofp-logs.tar.bz2
if-no-files-found: error

Expand Down Expand Up @@ -67,16 +67,28 @@ jobs:
asset_name: sofp.pdf
asset_content_type: application/pdf

- name: Upload sofp-draft.pdf
- name: Upload sofp-10pt.pdf
if: contains(github.ref, 'refs/tags/v')
id: upload-sofp
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./sofp-src/sofp-10pt.pdf
asset_name: sofp-10pt.pdf
asset_content_type: application/pdf

- name: Upload sofp-vol1.pdf
if: contains(github.ref, 'refs/tags/v')
id: upload-sofp-draft
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./sofp-src/sofp-draft.pdf
asset_name: sofp-draft.pdf
asset_path: ./sofp-src/sofp-vol1.pdf
asset_name: sofp-vol1.pdf
asset_content_type: application/pdf

- name: Upload sofp-3page-cover.pdf
Expand All @@ -91,3 +103,15 @@ jobs:
asset_name: sofp-3page-cover.pdf
asset_content_type: application/pdf

- name: Upload sofp-vol1-3page-cover.pdf
if: contains(github.ref, 'refs/tags/v')
id: upload-sofp-vol1-cover
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./sofp-src/sofp-vol1-3page-cover.pdf
asset_name: sofp-vol1-3page-cover.pdf
asset_content_type: application/pdf

2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -91,6 +91,8 @@ on-demand printing at lulu.com or elsewhere.

If you want to build from source, currently you need `LyX` 2.3.x and `pdftk` installed.

Change to the directory `sofp-src`.

The command `bash make_sofp_pdf.sh` builds PDF files `sofp.pdf` and `sofp-draft.pdf`.
The first file is a full draft with some unfinished chapters,
the second file contains only finished and proofread chapters.
Expand Down
4 changes: 2 additions & 2 deletions sofp-src/README.md
Expand Up @@ -10,7 +10,7 @@ with the goal of building theoretical foundations that are valuable to practitio
At this time, the video tutorials are obsolete because the book already covers all their material and much more.
Some notations in the video tutorials have been changed in the book, and some mistakes have been corrected.

The material below is kept for reference only. Refer to the book for current status.
The material below is obsolete and kept for reference only. Refer to the book for current status.

## Scope of the tutorial series

Expand Down Expand Up @@ -248,7 +248,7 @@ Contents in brief:
- How to infer the most generic (parametric) types for higher-order functions
- Worked examples and exercises

**Note**: There was an error in the last exercise as shown in the video -- it had no solution.
**Note**: There was an error in the last exercise as shown in the video -- it had no solutions.
Please use the exercises from the current version of the PDF slides.

## Chapter 3, part 2: Disjunction types
Expand Down
13 changes: 7 additions & 6 deletions sofp-src/book_cover/sofp-back-cover-no-bg.tex.src
@@ -1,6 +1,6 @@
\onecolumn
\thispagestyle{empty}
\newgeometry{top=3cm, left=2.5cm, right=3.9cm,bottom=2cm}
\newgeometry{top=2cm, left=2.5cm, right=3.9cm,bottom=1cm}

\begin{wrapfigure}{l}{0.4\columnwidth}
\includegraphics[width=0.4\columnwidth]{monads_evil_face}
Expand All @@ -19,15 +19,15 @@ to other FP languages.

The book's topics include working with FP-style collections; reasoning about recursive
functions and types; the Curry-Howard correspondence; laws, structural
analysis, and code for functors, monads, and other typeclasses built upon exponential-polynomial data types; techniques
of symbolic derivation and proof;
analysis, and code for functors, monads, and other typeclasses based on exponential-polynomial data types;
techniques of symbolic derivation and proof;
free typeclass constructions; and
parametricity theorems.

Long and difficult, yet boring explanations are logically
developed in excruciating detail through NUMBEROFCODESNIPPETS
Scala code snippets, NUMBEROFSTATEMENTS statements with step-by-step
derivations, NUMBEROFDIAGRAMS diagrams, NUMBEROFEXAMPLES solved examples
derivations, NUMBEROFDIAGRAMS diagrams, NUMBEROFEXAMPLES examples
with tested Scala code, and NUMBEROFEXERCISES exercises. Discussions
build upon each chapter's material further.

Expand All @@ -45,11 +45,12 @@ and explains the use of parametricity for reasoning about the Church encoding an
Readers should have a working knowledge of programming; e.g.,
be able to write code that prints the number of distinct words in
a sentence. The difficulty of this book's mathematical derivations
is at the level of undergraduate calculus, similar to that of multiplying
is at the level of undergraduate multivariate calculus, similar to that of multiplying
matrices or simplifying the expressions:
\[
\frac{1}{x-2}-\frac{1}{x+2}\quad\text{ and }\quad\frac{d}{dx}\left((x+1)f(x)e^{-x}\right)\quad.
\]

Sergei Winitzki received a Ph.D. in theoretical physics. After a career in academic research, he currently works as a software engineer.
The author received a Ph.D. in theoretical physics. After a career in academic research, he works as a software engineer.

%\vspace{0.2cm}\hspace*{\fill}\includegraphics[scale=1.0]{barcode}
2 changes: 2 additions & 0 deletions sofp-src/book_cover/sofp-cover-page-no-bg.tex
Expand Up @@ -11,6 +11,8 @@
\vspace{0.4in}
\centerline{\fontsize{25pt}{25pt}\selectfont{\textit{A tutorial, with examples in Scala}}}

% End of title.

\begin{textblock*}{8cm}(11.5cm,21cm)
\fontsize{18pt}{18pt}\selectfont{\textsf{Sergei Winitzki}}
\end{textblock*}
2 changes: 1 addition & 1 deletion sofp-src/book_cover/sofp-cover-parameters.tex
Expand Up @@ -18,7 +18,7 @@
% -- Ingram: page count MUST be divisible by 2.
% -- Blurb : page count MUST be divisible by 6.
% Add blank pages as needed in final PDF generations!
\pgfmathsetmacro\TotalPageCount{875}% Must be manually entered
\pgfmathsetmacro\TotalPageCount{TOTALPAGES}% Must be manually entered
\pgfmathsetmacro\PaperWidthPt{7.444in}%
\pgfmathsetmacro\PaperHeightPt{9.68in}%

Expand Down
5 changes: 3 additions & 2 deletions sofp-src/book_cover/sofp-make-cover.sh
@@ -1,8 +1,9 @@
#!/bin/bash

# Prepare the three cover pages in parallel.
for f in sofp-spine sofp-back-cover sofp-front-cover; do
pdflatex --interaction=batchmode "$f"
pdflatex --interaction=batchmode "$f" &
done
wait # Wait until all 3 cover pages are done.
pdflatex --interaction=batchmode sofp-3page-cover


5 changes: 3 additions & 2 deletions sofp-src/book_cover/sofp-spine.tex
Expand Up @@ -27,7 +27,8 @@
%\TileWallPaper{\CoverHeight in}{\SpineWidth in + 12cm}{spine-background.png}
%\pagecolor{yellow!20}
\vspace*{\fill}
\begin{minipage}{0.7\linewidth}\begin{center}\vspace*{-1.0mm} \fontsize{32pt}{32pt}\selectfont\textbf{{The Science of Functional Programming}}\end{center}\end{minipage}
\begin{minipage}{0.3\linewidth}\begin{center}\vspace*{-1.0mm} \fontsize{20pt}{20pt}\selectfont\textsf{Winitzki}\end{center}\end{minipage}
\begin{minipage}{0.7\linewidth}\begin{center}\vspace*{-1.0mm} \fontsize{16pt}{16pt}\selectfont\textbf{{%
The Science of Functional Programming}}\end{center}\end{minipage}
\begin{minipage}{0.3\linewidth}\begin{center}\vspace*{-1.0mm} \fontsize{12pt}{12pt}\selectfont\textsf{Winitzki}\end{center}\end{minipage}
\vspace*{\fill}
\end{document}
Binary file added sofp-src/book_cover/vol1_isbn_barcode.pdf
Binary file not shown.
Binary file added sofp-src/book_cover/vol2_isbn_barcode.pdf
Binary file not shown.
Binary file added sofp-src/book_cover/vol3_isbn_barcode.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions sofp-src/check_and_make_draft.sh
Expand Up @@ -99,3 +99,9 @@ function create_draft {

# Create the lulu.com draft file by selecting the chapters that have been proofread.
create_draft $name $draft.pdf

# Attach sources to the draft file.
if test -s $name-src.tar.bz2 && test -s $draft.pdf; then "$pdftk" $draft.pdf attach_files "$name-src.tar.bz2" output $draft-src.pdf
else
echo Not attaching sources to draft since no source file $name-src.tar.bz2 is found or no $draft.pdf is found.
fi
2 changes: 2 additions & 0 deletions sofp-src/excluded_words
Expand Up @@ -540,6 +540,7 @@
^bifunctorQ$
^bifunctors$
^bigM$
^bijective$
^bimap$
^binSearch$
^binaryOp$
Expand Down Expand Up @@ -1286,6 +1287,7 @@
^subarray$
^subarrays$
^subarrays3$
^subclasses$
^subexpressions$
^subindices$
^subsequence$
Expand Down
47 changes: 25 additions & 22 deletions sofp-src/make_sofp_pdf.sh
Expand Up @@ -2,7 +2,8 @@

# Requires pdftk and lyx.
# Get lyx from www.lyx.org
# For Mac, get pdftk from https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg
# For Mac, get pdftk from https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg or else it may not work
# For Windows, get pdftk from https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_free-2.02-win-setup.exe

name="sofp"

Expand Down Expand Up @@ -63,7 +64,7 @@ function add_color {
local texsrc="$1"
# Insert color comments into displayed equation arrays. Also, in some places the green color was inserted; replace by `greenunder`.
# Example of inserted color: {\color{greenunder}\text{outer-interchange law for }M:}\quad &
LC_ALL=C sed -i.bak -e 's|\\color{green}|\\color{greenunder}|; s|^\(.*\\text{[^}]*}.*:\)\( *\\quad \& \)|{\\color{greenunder}\1}\2|' "$texsrc"
LC_ALL=C sed -i.bak -e 's|\\color{green}|\\color{greenunder}|; s|^\(.*\\text{[^}]*}.*:\)\( *\\quad \& \)|{\\color{greenunder}\1}\2|; s|\(\& *\\quad\)\(.*\\text{[^}]*}.*: *\)\(\\quad\\\\\)$|\1{\\color{greenunder}\2}\3|' "$texsrc"
# Insert color background into all displayed equations. This is disabled because it does not always produce visually good results.
if false; then
LC_ALL=C sed -i.bak -E -e ' s!\\begin\{(align.?|equation)\}!\\begin{empheq}[box=\\mymathbgbox]{\1}!; s!\\end\{(align.?|equation)\}!\\end{empheq}!; ' "$texsrc"
Expand Down Expand Up @@ -156,12 +157,14 @@ for f in sofp-cover-page-no-bg.tex sofp-cover-page.tex sofp-back-cover.tex sofp-
# Check whether the sources have changed. If so, create a new sources archive and a new PDF file.
add_source_hashes $name.tex

# Prepare "$name-src.tar.bz2" with all sources.
assemble_sources &

echo "Creating a full PDF file..."

make_pdf_with_index "$name" # Output is $name.pdf, main file is $name.tex, and other .tex files are \include'd.
make_pdf_with_index "$name" # Output is $name.pdf, main file is $name.tex, and other .tex files are \include'd.

# Wait until assemble_sources is finished.
wait

if ! test -s "$name".pdf; then
Expand Down Expand Up @@ -192,18 +195,21 @@ total_pages=`pdfPages "$name".pdf`

echo Result is "$name.pdf", size `kbSize "$name.pdf"` bytes, with $total_pages pages.

bash prepare_10point.sh "$pdftk" &

bash prepare_volume.sh 1 "$pdftk" &
bash prepare_volume.sh 2 "$pdftk" &
bash prepare_volume.sh 3 "$pdftk" &

bash spelling_check.sh &

# Create the "clean draft" pdf file by selecting the chapters that have been proofread.
# Check page counts in the draft file and in individual chapters.
bash check_and_make_draft.sh
draft_pages=`pdfPages "$draft".pdf`
#bash check_and_make_draft.sh
#draft_pages=`pdfPages "$draft".pdf`
bash check-consistent-labels.sh
bash check-lines_with_displaymath_in_new_paragraph.sh

# Attach sources to the draft file.
if test -s $name-src.tar.bz2 && test -s $draft.pdf; then "$pdftk" $draft.pdf attach_files "$name-src.tar.bz2" output $draft-src.pdf
else
echo Not attaching sources to draft since no source file $name-src.tar.bz2 is found or no $draft.pdf is found.
fi
if [ x"$1" == x-nolulu ]; then
# Create a pdf file without references to lulu.com and without lulu.com's ISBN.
mv "$name".pdf "$name"-lulu.pdf
Expand All @@ -215,20 +221,17 @@ if [ x"$1" == x-nolulu ]; then
mv "$name"-lulu.pdf "$name".pdf
fi

if [ x"$1" == x-print ]; then
# Create a full pdf without hyperlinks, for printing on paper. Remove the cover image from first page and the back cover image.
mv "$name.pdf" "$name-hyperlinks.pdf"
LC_ALL=C sed -i.bak -e 's|colorlinks=true|colorlinks=false|; s|\\input{sofp-cover-page}||; s|\\input{sofp-back-cover-page}||; ' $name.tex
make_pdf_with_index $name fast
mv "$name.pdf" "$name-nohyperlinks.pdf"
mv "$name-hyperlinks.pdf" "$name.pdf"
fi
# Prepare an entire PDF file without hyperlinks.
#if [ x"$1" == x-print ]; then
# bash remove_hyperlinks.sh $name
#fi

bash spelling_check.sh

# Prepare the full 3-page book covers. Use $total_pages and not $draft_pages since the printed file has all unedited content as well.
sed -i.bak -e "s|TOTALPAGES|$total_pages|" book_cover/sofp-cover-parameters.tex
(cd book_cover; bash sofp-make-cover.sh)
# Prepare the full 3-page book covers. Use $total_pages of the whole pdf file and not $draft_pages since the printed file has all unedited content as well.
bash prepare_cover.sh "$name.pdf" "$pdftk" &

# Cleanup?
#rm -f $name*{idx,ind,aux,dvi,ilg,out,toc,log,ps,lof,lot,data}

# Wait for background jobs.
wait
19 changes: 19 additions & 0 deletions sofp-src/prepare_cover.sh
@@ -0,0 +1,19 @@
# Prepare the printable PDF file of volume v of the book. v = 1, 2, 3.

pdffile="$1"
pdftk="$2"

function pdfPages {
local file="$1"
"$pdftk" "$file" dump_data | fgrep NumberOfPages | sed -e 's,^.* ,,'
}

export LC_ALL=C

total_pages=`pdfPages "$pdffile"`

cd book_cover

sed -i.bak -e "s|TOTALPAGES|$total_pages|" sofp-cover-parameters.tex

bash sofp-make-cover.sh

0 comments on commit 52a14a2

Please sign in to comment.