diff --git a/sofp-src/cover/sofp-back-cover-no-bg.tex.src b/sofp-src/cover/sofp-back-cover-no-bg.tex.src index 939a73161..1670bd643 100644 --- a/sofp-src/cover/sofp-back-cover-no-bg.tex.src +++ b/sofp-src/cover/sofp-back-cover-no-bg.tex.src @@ -1,6 +1,6 @@ \onecolumn \thispagestyle{empty} -\newgeometry{top=2cm, left=2.5cm, right=3.9cm,bottom=1cm} +\newgeometry{top=2.5cm, left=2.5cm, right=3.9cm, bottom=1cm} \begin{wrapfigure}{l}{0.4\columnwidth} \includegraphics[width=0.4\columnwidth]{monads_evil_face} @@ -53,4 +53,5 @@ matrices or simplifying the expressions: 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} + +%\vspace{3.0cm}\hspace*{\fill}\colorbox{white}{\includegraphics[scale=1.0,width=50.8mm,height=30.5mm]{barcode}} diff --git a/sofp-src/cover/sofp-back-cover.tex b/sofp-src/cover/sofp-back-cover.tex index 3ee550b1d..19e7d2991 100644 --- a/sofp-src/cover/sofp-back-cover.tex +++ b/sofp-src/cover/sofp-back-cover.tex @@ -5,6 +5,7 @@ \usepackage{graphicx} \usepackage{pagecolor} \usepackage{changepage} +\usepackage{relsize} \geometry{ paperwidth=\CoverWidth in,% diff --git a/sofp-src/cover/vol1_isbn_barcode_embedded_fonts.pdf b/sofp-src/cover/vol1_isbn_barcode_embedded_fonts.pdf new file mode 100644 index 000000000..f9fa5bd0b Binary files /dev/null and b/sofp-src/cover/vol1_isbn_barcode_embedded_fonts.pdf differ diff --git a/sofp-src/cover/vol2_isbn_barcode_embedded_fonts.pdf b/sofp-src/cover/vol2_isbn_barcode_embedded_fonts.pdf new file mode 100644 index 000000000..c47ce1f32 Binary files /dev/null and b/sofp-src/cover/vol2_isbn_barcode_embedded_fonts.pdf differ diff --git a/sofp-src/cover/vol3_isbn_barcode_embedded_fonts.pdf b/sofp-src/cover/vol3_isbn_barcode_embedded_fonts.pdf new file mode 100644 index 000000000..419335ed5 Binary files /dev/null and b/sofp-src/cover/vol3_isbn_barcode_embedded_fonts.pdf differ diff --git a/sofp-src/lyx/sofp-applicative.lyx b/sofp-src/lyx/sofp-applicative.lyx index 8ca3a7d24..42f4fa44a 100644 --- a/sofp-src/lyx/sofp-applicative.lyx +++ b/sofp-src/lyx/sofp-applicative.lyx @@ -28713,21 +28713,11 @@ status open \begin_layout Plain Layout It is unknown how to characterize or enumerate all polynomial functors that - are monads (see Problems + are monads (see Problem \begin_inset space ~ \end_inset -\begin_inset CommandInset ref -LatexCommand ref -reference "par:Problem-monads-1" -plural "false" -caps "false" -noprefix "false" - -\end_inset - -– \begin_inset CommandInset ref LatexCommand ref reference "par:Problem-monads" diff --git a/sofp-src/lyx/sofp-summary.lyx b/sofp-src/lyx/sofp-summary.lyx index 7e9af90a8..c110b6b6c 100644 --- a/sofp-src/lyx/sofp-summary.lyx +++ b/sofp-src/lyx/sofp-summary.lyx @@ -3045,7 +3045,7 @@ do not store . \begin_inset Note Note -status open +status collapsed \begin_layout Plain Layout By Yoneda we have @@ -3181,14 +3181,56 @@ If Exercise \begin_inset CommandInset label LatexCommand label -name "par:Exercise-additional-13" +name "par:Problem-monads-1" \end_inset \begin_inset CommandInset ref LatexCommand ref -reference "par:Exercise-additional-13" +reference "par:Problem-monads-1" +plural "false" +caps "false" +noprefix "false" + +\end_inset + + +\end_layout + +\begin_layout Standard +\begin_inset Foot +status open + +\begin_layout Plain Layout +This was an open problem but it was solved by Hew Wolff. +\end_layout + +\end_inset + + Prove that +\begin_inset Formula $L^{A}\triangleq\bbnum 1+\underbrace{A\times A\times...\times A}_{n\text{ times}}$ +\end_inset + + cannot be made into a monad if +\begin_inset Formula $n\ge2$ +\end_inset + +. +\end_layout + +\begin_layout Subsubsection +Exercise +\begin_inset CommandInset label +LatexCommand label +name "par:Exercise-additional-13-1" + +\end_inset + + +\begin_inset CommandInset ref +LatexCommand ref +reference "par:Exercise-additional-13-1" plural "false" caps "false" noprefix "false" @@ -4541,87 +4583,7 @@ open problems \begin_layout Standard The author of this book does not know how to answer the following questions and also could not find any answers in existing books or papers. -\end_layout - -\begin_layout Subsubsection -Problem -\begin_inset CommandInset label -LatexCommand label -name "par:Problem-monads-1" - -\end_inset - - -\begin_inset CommandInset ref -LatexCommand ref -reference "par:Problem-monads-1" -plural "false" -caps "false" -noprefix "false" - -\end_inset - - -\end_layout - -\begin_layout Standard -Do all polynomial functors of the form -\begin_inset Formula $P_{n}^{A}\triangleq\bbnum 1+\overbrace{A\times A\times...\times A}^{n\text{ times, }n\ge2}$ -\end_inset - - fail to be monads? An example is the functor -\begin_inset Formula $P_{2}^{A}\triangleq\bbnum 1+A\times A$ -\end_inset - -, which is not a monad because all possible implementations of -\begin_inset listings -inline true -status open - -\begin_layout Plain Layout - -pure -\end_layout - -\end_inset - - and -\begin_inset listings -inline true -status open - -\begin_layout Plain Layout - -flatMap -\end_layout - -\end_inset - - methods for -\begin_inset Formula $P_{2}$ -\end_inset - - fail the monad laws. -\begin_inset Foot -status open - -\begin_layout Plain Layout -See discussion here: -\family typewriter - -\begin_inset CommandInset href -LatexCommand href -target "https://stackoverflow.com/questions/49742377" -literal "false" - -\end_inset - - -\end_layout - -\end_inset - - + \end_layout \begin_layout Subsubsection @@ -4737,6 +4699,33 @@ not obtained by a chain of these constructions? \end_layout +\begin_layout Standard +For example, functors of the form +\begin_inset Formula $L^{A}\triangleq\bbnum 1+A\times A$ +\end_inset + +, +\begin_inset Formula $L^{A}\triangleq\bbnum 1+A\times A\times A$ +\end_inset + +, etc., cannot be obtained via these constructions. + All those functors are not monads (see Exercise +\begin_inset space ~ +\end_inset + + +\begin_inset CommandInset ref +LatexCommand ref +reference "par:Problem-monads-1" +plural "false" +caps "false" +noprefix "false" + +\end_inset + +). +\end_layout + \begin_layout Subsubsection Problem \begin_inset CommandInset label diff --git a/sofp-src/scripts/clean.sh b/sofp-src/scripts/clean.sh index 61fc5a92e..4cf095bda 100644 --- a/sofp-src/scripts/clean.sh +++ b/sofp-src/scripts/clean.sh @@ -1 +1 @@ -rm -rf build vol1 vol2 vol3 pdf* mdoc sofp-*.pdf +rm -rf build tex vol1 vol2 vol3 pdf* mdoc sofp-*.pdf sofp.pdf diff --git a/sofp-src/scripts/prepare_volume.sh b/sofp-src/scripts/prepare_volume.sh index e0dcceb53..742380bd1 100644 --- a/sofp-src/scripts/prepare_volume.sh +++ b/sofp-src/scripts/prepare_volume.sh @@ -9,15 +9,15 @@ function pdfPages { } vol1_ISBN="ISBN (vol.~1): 978-1-4710-4004-7" -vol1_ISBN_barcode="vol1_isbn_barcode.pdf" +vol1_ISBN_barcode="vol1_isbn_barcode_embedded_fonts.pdf" vol1_url="https://www.lulu.com/shop/sergei-winitzki/the-science-of-functional-programming-part-i/paperback/product-dyyq2zm.html" vol2_ISBN="ISBN (vol.~2): 978-1-4461-9146-0" -vol2_ISBN_barcode="vol2_isbn_barcode.pdf" +vol2_ISBN_barcode="vol2_isbn_barcode_embedded_fonts.pdf" vol2_url="https://www.lulu.com/shop/sergei-winitzki/the-science-of-functional-programming-part-ii/paperback/product-655e7wm.html" vol3_ISBN="ISBN (vol.~3): 978-1-4461-9136-1" -vol3_ISBN_barcode="vol3_isbn_barcode.pdf" +vol3_ISBN_barcode="vol3_isbn_barcode_embedded_fonts.pdf" vol3_url="https://www.lulu.com/shop/sergei-winitzki/the-science-of-functional-programming-part-ii/paperback/product-p668z4q.html" v=$1 @@ -124,7 +124,7 @@ esac echo "Using volume $v ISBN '$isbn'" sed -i.bak -e 's|\({\\footnotesize{}\)ISBN: [^}]*\(}\\\\\)|\1'"$isbn"'\2|;' $dir/$name.tex # Add barcode to back cover. - sed -i.bak -e 's|%\(.*\){barcode}.*|\1{'"$barcode"'}|' $dir/sofp-back-cover-no-bg.tex + sed -i.bak -e 's|%\(.*\){barcode}\(.*\)$|\1{'"$barcode"'}\2|' $dir/sofp-back-cover-no-bg.tex mv $dir/$name.tex $dir/sofp.tex diff --git a/sofp-src/tex/chapter3-picture.pdf b/sofp-src/tex/chapter3-picture.pdf index db01aecb8..edd70840f 100644 Binary files a/sofp-src/tex/chapter3-picture.pdf and b/sofp-src/tex/chapter3-picture.pdf differ diff --git a/sofp-src/tex/sofp-applicative.tex b/sofp-src/tex/sofp-applicative.tex index 68ffd70a0..9e0ec2100 100644 --- a/sofp-src/tex/sofp-applicative.tex +++ b/sofp-src/tex/sofp-applicative.tex @@ -4711,7 +4711,7 @@ \subsection{Relationship between monads and applicative functors} functors with monoidal fixed types. (All our examples of non-applicative functors involve non-polynomial functors.) But we have seen that not all polynomial functors are monads.\footnote{It is unknown how to characterize or enumerate all polynomial functors -that are monads (see Problems~\ref{par:Problem-monads-1}\textendash \ref{par:Problem-monads}).} Example~\ref{subsec:Example-applicative-not-monad} shows a simple +that are monads (see Problem~\ref{par:Problem-monads}).} Example~\ref{subsec:Example-applicative-not-monad} shows a simple applicative functor\index{applicative functor!not a monad} ($L^{A}\triangleq\bbnum 1+A\times A$) that does \emph{not} have a lawful monad implementation (Exercise~\ref{subsec:Exercise-1-monads-7-not-a-monad}). diff --git a/sofp-src/tex/sofp-back-cover-no-bg.tex b/sofp-src/tex/sofp-back-cover-no-bg.tex index 5d96f2625..8ae27bc00 100644 --- a/sofp-src/tex/sofp-back-cover-no-bg.tex +++ b/sofp-src/tex/sofp-back-cover-no-bg.tex @@ -1,6 +1,6 @@ \onecolumn \thispagestyle{empty} -\newgeometry{top=2cm, left=2.5cm, right=3.9cm,bottom=1cm} +\newgeometry{top=2.5cm, left=2.5cm, right=3.9cm, bottom=1cm} \begin{wrapfigure}{l}{0.4\columnwidth} \includegraphics[width=0.4\columnwidth]{monads_evil_face} @@ -28,7 +28,7 @@ developed in excruciating detail through 1906 Scala code snippets, 192 statements with step-by-step derivations, 104 diagrams, 223 examples -with tested Scala code, and 309 exercises. Discussions +with tested Scala code, and 310 exercises. Discussions build upon each chapter\textsf{'}s material further. Beginners in FP will find tutorials about the \texttt{map}/\texttt{reduce} @@ -53,4 +53,5 @@ 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} + +%\vspace{3.0cm}\hspace*{\fill}\colorbox{white}{\includegraphics[scale=1.0,width=50.8mm,height=30.5mm]{barcode}} diff --git a/sofp-src/tex/sofp-filterable.tex b/sofp-src/tex/sofp-filterable.tex index 958f64ff8..126a13533 100644 --- a/sofp-src/tex/sofp-filterable.tex +++ b/sofp-src/tex/sofp-filterable.tex @@ -3628,7 +3628,7 @@ \subsubsection{Statement \label{subsec:Statement-recursive-filterable-contrafunc } \end{lstlisting} \[ -\xymatrix{S^{B,F^{B}}\ar[r]\sp(0.525){\text{liftOpt}_{S}(f^{:A\rightarrow\bbnum 1+B})}\ar[rd]\sb(0.45){\text{liftOpt}_{F}(f)\triangleq~~~} & S^{A,F^{B}}\ar[d]\sp(0.45){\big(\overline{\text{liftOpt}_{F}}(f)\big)^{\uparrow S^{A,\bullet}}}\\ +\xymatrix{S^{B,F^{B}}\ar[r]\sp(0.525){\text{liftOpt}_{S}(f^{:A\rightarrow\bbnum 1+B})}\ar[rd]\sb(0.45){\text{liftOpt}_{F}(f)\triangleq~~~} & S^{A,F^{B}}\ar[d]\sp(0.4){\big(\overline{\text{liftOpt}_{F}}(f)\big)^{\uparrow S^{A,\bullet}}}\\ \xyScaleY{1.8pc}\xyScaleX{6pc} & S^{A,F^{A}} } \] @@ -3674,7 +3674,7 @@ \subsubsection{Statement \label{subsec:Statement-recursive-filterable-contrafunc with respect to lifting in the type parameter $A$ of $S^{A,R}$. That law is: \[ -\xymatrix{S^{B,R}\ar[r]\sp(0.5){\text{liftOpt}_{S}(f^{:A\rightarrow\bbnum 1+B})}\ar[d]\sb(0.55){(h^{:R\rightarrow R^{\prime}})^{\uparrow S^{B,\bullet}}} & S^{A,R}\ar[d]\sp(0.55){h^{\uparrow S^{A,\bullet}}}\\ +\xymatrix{S^{B,R}\ar[r]\sp(0.5){\text{liftOpt}_{S}(f^{:A\rightarrow\bbnum 1+B})}\ar[d]\sb(0.5){(h^{:R\rightarrow R^{\prime}})^{\uparrow S^{B,\bullet}}} & S^{A,R}\ar[d]\sp(0.4){h^{\uparrow S^{A,\bullet}}}\\ \xyScaleY{1.8pc}\xyScaleX{6.0pc}S^{B,R^{\prime}}\ar[r]\sp(0.45){\text{liftOpt}_{S}(f)} & S^{A,R^{\prime}} } \] @@ -4332,7 +4332,7 @@ \subsection{Naturality laws and natural transformations\label{subsec:Naturality- that requirement as an equation called the \textbf{naturality law}\index{naturality law!of headOption@of \texttt{headOption}} of \lstinline!headOption!: \[ -\xymatrix{\text{List}^{A}\ar[r]\sp(0.55){\text{headOpt}^{A}}\ar[d]\sb(0.5){(f^{:A\rightarrow B})^{\uparrow\text{List}}} & \text{Opt}^{A}\ar[d]\sb(0.4){f^{\uparrow\text{Opt}}}\\ +\xymatrix{\text{List}^{A}\ar[r]\sp(0.55){\text{headOpt}^{A}}\ar[d]\sb(0.5){(f^{:A\rightarrow B})^{\uparrow\text{List}}} & \text{Opt}^{A}\ar[d]\sp(0.45){f^{\uparrow\text{Opt}}}\\ \xyScaleY{1.6pc}\xyScaleX{4.5pc}\text{List}^{B}\ar[r]\sp(0.55){\text{headOpt}^{B}} & \text{Opt}^{B} } \] diff --git a/sofp-src/tex/sofp-summary.tex b/sofp-src/tex/sofp-summary.tex index 172ebc691..a13fe14fa 100644 --- a/sofp-src/tex/sofp-summary.tex +++ b/sofp-src/tex/sofp-summary.tex @@ -457,7 +457,13 @@ \subsubsection{Exercise \label{par:Exercise-additional-12}\ref{par:Exercise-addi If $M$ is a commutative monad then $M\circ M$ is also a lawful commutative monad. -\subsubsection{Exercise \label{par:Exercise-additional-13}\ref{par:Exercise-additional-13}} +\subsubsection{Exercise \label{par:Problem-monads-1}\ref{par:Problem-monads-1}} + +\footnote{This was an open problem but it was solved by Hew Wolff.} +Prove that $L^{A}\triangleq\bbnum 1+\underbrace{A\times A\times...\times A}_{n\text{ times}}$ +cannot be made into a monad if $n\ge2$. + +\subsubsection{Exercise \label{par:Exercise-additional-13-1}\ref{par:Exercise-additional-13-1}} If $M$ is a commutative monad and $W$ is a commutative monoid then the monoid $M^{W}$ is commutative. @@ -632,14 +638,7 @@ \subsection{Open problems\index{open problems}} The author of this book does not know how to answer the following questions and also could not find any answers in existing books or -papers. - -\subsubsection{Problem \label{par:Problem-monads-1}\ref{par:Problem-monads-1}} - -Do all polynomial functors of the form $P_{n}^{A}\triangleq\bbnum 1+\overbrace{A\times A\times...\times A}^{n\text{ times, }n\ge2}$ -fail to be monads? An example is the functor $P_{2}^{A}\triangleq\bbnum 1+A\times A$, -which is not a monad because all possible implementations of \lstinline!pure! -and \lstinline!flatMap! methods for $P_{2}$ fail the monad laws.\footnote{See discussion here: \texttt{\href{https://stackoverflow.com/questions/49742377}{https://stackoverflow.com/questions/49742377}}} +papers. \subsubsection{Problem \label{par:Problem-monads}\ref{par:Problem-monads}} @@ -660,6 +659,10 @@ \subsubsection{Problem \label{par:Problem-monads}\ref{par:Problem-monads}} there any polynomial monads \emph{not} obtained by a chain of these constructions? +For example, functors of the form $L^{A}\triangleq\bbnum 1+A\times A$, +$L^{A}\triangleq\bbnum 1+A\times A\times A$, etc., cannot be obtained +via these constructions. All those functors are not monads (see Exercise~\ref{par:Problem-monads-1}). + \subsubsection{Problem \label{subsec:Problem-co-pointed-applicative}\ref{subsec:Problem-co-pointed-applicative}} By Statement~\ref{subsec:Statement-co-pointed-applicative-example}, diff --git a/sofp-src/tex/sofp-typeclasses.tex b/sofp-src/tex/sofp-typeclasses.tex index 6f5682a44..a82f35937 100644 --- a/sofp-src/tex/sofp-typeclasses.tex +++ b/sofp-src/tex/sofp-typeclasses.tex @@ -2889,7 +2889,7 @@ \subsection{Pointed functors: motivation and laws\label{subsec:Pointed-functors- Since both sides of the law are functions applied to an arbitrary value $x^{:A}$, we can omit $x$ and rewrite the law as: \begin{equation} -\text{for any }f^{:A\rightarrow B}:\quad\quad\text{pu}_{F}\bef f^{\uparrow F}=f\bef\text{pu}_{F}\quad.\label{eq:naturality-law-of-pure} +\text{for any }f^{:A\rightarrow B}:\quad\text{pu}_{F}\bef f^{\uparrow F}=f\bef\text{pu}_{F}\quad.\label{eq:naturality-law-of-pure} \end{equation} \[ \xymatrix{\xyScaleY{2.0pc}\xyScaleX{4.0pc}A\ar[r]\sp(0.5){\text{pu}_{F}}\ar[d]\sb(0.45){f} & F^{A}\ar[d]\sp(0.45){f^{\uparrow F}}\\ diff --git a/sofp-src/tex/sofp.tex b/sofp-src/tex/sofp.tex index 031daa1d3..d25c90a53 100644 --- a/sofp-src/tex/sofp.tex +++ b/sofp-src/tex/sofp.tex @@ -1,4 +1,4 @@ -%% LyX 2.3.6.2 created this file. For more info, see http://www.lyx.org/. +%% LyX 2.3.7 created this file. For more info, see http://www.lyx.org/. %% Do not edit unless you really know what you are doing. \documentclass[10pt,russian,english,openright,numbers=noenddot,index=totoc,bibliography=totoc,listof=totoc,fontsize=12pt]{scrbook} \usepackage{amsmath} @@ -336,9 +336,9 @@ {\footnotesize{}ISBN (e-book): 978-0-359-76877-6}\\ {\footnotesize{}ISBN: 978-0-359-76877-6}\\ \\ -{\scriptsize{}Source hash (sha256): 3c11991097dc72ed4cac251fc86e6ababb7ee20fe75421517a164b6032c7b24a}\\ -{\scriptsize{}Git commit: 5bf853f262fadf3c192f9ab6be13ca4deb99b43d}\\ -{\scriptsize{}PDF file built on Thu, 22 Aug 2024 21:37:50 +0200 by pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2021) on Darwin}\\ +{\scriptsize{}Source hash (sha256): cc147a546a04a29eaca33d732eae46d8a4e2b52b357f6bd30f4f99f07d1e6863}\\ +{\scriptsize{}Git commit: 8af5847655dd43ee6c73a1e5f969665bfaf3e908}\\ +{\scriptsize{}PDF file built on Wed, 04 Sep 2024 11:42:44 +0200 by pdfTeX 3.141592653-2.6-1.40.25 (TeX Live 2023) on Darwin}\\ ~\\ {\scriptsize{}Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, @@ -376,7 +376,7 @@ developed in excruciating detail through 1906 Scala code snippets, 192 statements with step-by-step derivations, 104 diagrams, 223 examples with tested Scala -code, and 309 exercises. Discussions build upon each +code, and 310 exercises. Discussions build upon each chapter's material further.}\\ {\scriptsize{}}\\ {\scriptsize{}Beginners in FP will find tutorials about the map/reduce