+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
a78a319
wip MonadDSL
winitzki Nov 29, 2024
22ea410
wip
winitzki Nov 29, 2024
3f8383b
wip
winitzki Nov 30, 2024
73f229e
wip
winitzki Dec 3, 2024
54c525b
wip
winitzki Dec 3, 2024
3324d17
fix formatting in chapter 2
winitzki Dec 4, 2024
00ddf57
wip
winitzki Dec 6, 2024
71f4a2e
add A H + F
winitzki Dec 10, 2024
17faeb0
add examples and tests to exercise 2.5.2.11
winitzki Dec 14, 2024
2619d56
wip
winitzki Dec 29, 2024
ada895d
fix some typo and add exercise for NEL
winitzki Jan 1, 2025
0709839
wip free monad
winitzki Jan 1, 2025
e1386c1
wip
winitzki Jan 2, 2025
493b184
wip
winitzki Jan 2, 2025
c433939
wip
winitzki Jan 2, 2025
49c35ec
wip
winitzki Jan 2, 2025
3794097
wip
winitzki Jan 3, 2025
0bcbf01
wip
winitzki Jan 3, 2025
db4a78d
wip
winitzki Jan 3, 2025
2229a83
wip
winitzki Jan 5, 2025
2278e45
wip
winitzki Jan 7, 2025
8f7d46f
wip
winitzki Jan 8, 2025
114346a
wip
winitzki Jan 8, 2025
e320640
wip
winitzki Jan 8, 2025
d4c80ca
wip
winitzki Jan 11, 2025
c201ddc
add amazon steps language slide
winitzki Jan 11, 2025
d6883c4
wip
winitzki Jan 11, 2025
66558b8
wip
winitzki Jan 11, 2025
9037b28
wip
winitzki Jan 12, 2025
d9202b6
wip
winitzki Jan 12, 2025
a29fa61
wip some proofs for E-monad algebra properties
winitzki Jan 12, 2025
5dee638
wip
winitzki Jan 12, 2025
5c5ddb6
wip
winitzki Jan 13, 2025
c2db26f
add link to cofree traversable
winitzki Jan 13, 2025
77c8c12
proof of monad algebra constructions
winitzki Jan 13, 2025
25b8cd3
wip
winitzki Jan 13, 2025
fb40b28
wip
winitzki Jan 13, 2025
1742127
wip
winitzki Jan 13, 2025
b4f086e
fix formatting in applicative chapter, after changes
winitzki Jan 16, 2025
aebc0ea
move exercise to chapter 8
winitzki Jan 23, 2025
bd0c55e
wip
winitzki Jan 23, 2025
2e0d4a4
co-P-typeclasses
winitzki Jan 23, 2025
1893ffe
wip
winitzki Jan 23, 2025
d575d88
update tex
winitzki Jan 23, 2025
fc11d17
wip
winitzki Jan 23, 2025
721ac39
fix formatting
winitzki Jan 24, 2025
bfa78a1
wip
winitzki Jan 28, 2025
da7e91b
write exercises about p->a + q->a
winitzki Feb 22, 2025
abb597b
wip
winitzki Feb 22, 2025
0bc38cf
wip JOC theorem
winitzki Feb 27, 2025
41cb0b3
wip
winitzki Feb 28, 2025
881d871
wip
winitzki Feb 28, 2025
1f38105
wip
winitzki Mar 3, 2025
1bbaf46
add a clarification about "commutative diagrams"
winitzki Mar 5, 2025
a0ec48c
wip more proofs
winitzki Mar 6, 2025
cb27a1b
wip more detail about the parametricity proofs
winitzki Mar 6, 2025
e5998ac
finish the proof for f F 0
winitzki Mar 6, 2025
6116faa
fix the comment about palindrome integers
winitzki Mar 7, 2025
a685b8a
wip
winitzki Mar 7, 2025
c0567f4
more detail about higher-order functions
winitzki Mar 12, 2025
aa339ef
wip
winitzki Mar 12, 2025
07d194e
formatting change
winitzki Mar 18, 2025
ddc4577
update glossary
winitzki Mar 21, 2025
f4407e0
more explanations about curry-howard
winitzki Mar 24, 2025
465332f
wip
winitzki Mar 25, 2025
c66b40c
recursion scheme -> pattern functor
winitzki Apr 5, 2025
a2418aa
wip
winitzki Apr 6, 2025
d38646e
remove "recursion schemes" from chapter 8
winitzki Apr 6, 2025
235bf2f
fixing the last hole in monad transformer chapter
winitzki Apr 9, 2025
f1a4cd6
wip
winitzki Apr 9, 2025
b4f57bc
theorem about free monad stack
winitzki May 4, 2025
b67924e
minor fix
winitzki May 6, 2025
66d0085
wip
winitzki May 8, 2025
136c75c
remove PTVF from appendix
winitzki May 9, 2025
6c04ab5
finish proof for composition of free monads
winitzki May 13, 2025
7dd22d6
cosmetic change
winitzki May 14, 2025
42ed6c0
wip P-typeclass theory
winitzki May 14, 2025
a71f444
wip
winitzki May 15, 2025
83e43a6
wip
winitzki May 15, 2025
76660ee
significantly simplify the proof of law properties
winitzki May 18, 2025
0809d84
wip proof of laws of E^T
winitzki May 19, 2025
3523d1c
wip fixing mistakes
winitzki May 19, 2025
4dd4990
wip some more proofs about universally quantified types
winitzki May 20, 2025
a8af42e
wip fixing the proof of the difficult theorem
winitzki May 21, 2025
0306049
minor formatting fixes
winitzki May 22, 2025
3b97cfd
minor formatting fixes
winitzki May 22, 2025
cb85d69
wip explanation about typeclasses and OOIs
winitzki Jun 9, 2025
74a780e
eip
winitzki Jun 9, 2025
54cfb56
edit the discussion about typeclasses, OOIs, and ADTs
winitzki Jun 10, 2025
c8775b9
wip
winitzki Jun 12, 2025
38cf950
minor updates to summary and typeclasses
winitzki Jun 17, 2025
8560cde
start working on the summary chapter
winitzki Jun 18, 2025
eb0f555
wip summary
winitzki Jun 19, 2025
eecc9ac
wip summary, and describe the monad co-product transformer
winitzki Jun 23, 2025
60d4d31
proof of the Jaskelioff-O'Connor theorem
winitzki Jun 25, 2025
6740a33
wip proof of monad type equivalence
winitzki Jun 26, 2025
5547fb8
wip proof of M -> M identity
winitzki Jun 26, 2025
394983c
wip proof of M -> M identity
winitzki Jun 27, 2025
f7719e8
wip M-> M proof
winitzki Jun 28, 2025
94190e0
wip finished the proof of M->M identity
winitzki Jun 30, 2025
362709b
add derivation in Scala syntax
winitzki Jun 30, 2025
ffddd24
more details
winitzki Jun 30, 2025
f79788e
remove references to the nondegeneracy law
winitzki Jun 30, 2025
cf847ef
wip fixing the proof of disjunctivity lemma
winitzki Jul 2, 2025
1038576
wip
winitzki Jul 7, 2025
c67e674
wip simplification of ((a -> a) -> a) -> a
winitzki Jul 8, 2025
6f8b75f
wip new example
winitzki Jul 8, 2025
7930a06
wip adding more material about existential types
winitzki Jul 18, 2025
10d786b
wip proofs of pack identity law
winitzki Jul 20, 2025
2861807
wip proofs of universal and existential types
winitzki Jul 20, 2025
f9c43ea
more detail about the universal quantifier
winitzki Jul 21, 2025
33c3610
minor fixes
winitzki Jul 21, 2025
5b834ba
cleanup, remove invalid claims
winitzki Jul 26, 2025
4842a4c
update pdf
winitzki Jul 26, 2025
b75c3dc
move Church encoding to appendix
winitzki Jul 27, 2025
63126f9
wip
winitzki Jul 27, 2025
903a54b
wip towards fixpoint-preserving functions
winitzki Jul 27, 2025
7c66e55
wip
winitzki Jul 27, 2025
777c5e8
wip fixing the chapter3-figure problem
winitzki Jul 29, 2025
f91f377
fix formatting issues in chapter 3
winitzki Jul 29, 2025
dbe01a6
towards explanation of fixpoint-preserving property
winitzki Jul 29, 2025
ac8397a
wip fixpoints explanation
winitzki Jul 29, 2025
8dbb612
reformat chapter 3 again after some breakage
winitzki Jul 30, 2025
e99e532
minor correction
winitzki Jul 30, 2025
7d24f9c
fixing some index entries
winitzki Jul 30, 2025
09f1fcf
wip more index entries
winitzki Jul 30, 2025
923ea22
minor fix
winitzki Jul 30, 2025
6341dd6
minor correction
winitzki Jul 31, 2025
037abf5
update pdf
winitzki Jul 31, 2025
b04973d
fix chapter 3 with explanations about flatMap
winitzki Jul 31, 2025
1ad7576
more explanations about natural transformations
winitzki Aug 3, 2025
3adebbf
wip fixing the unclear explanations for deflate
winitzki Aug 5, 2025
54310b2
wip
winitzki Aug 5, 2025
37506bc
corrections after talking to Vadim
winitzki Aug 7, 2025
e365193
add Vadim to acknowledgments
winitzki Aug 7, 2025
844bfdc
one more clarifiaction about naturality law of filter
winitzki Aug 8, 2025
04fb678
wip proofs of Church encoding
winitzki Aug 9, 2025
81a4d50
wip fixpoint-preserving functions
winitzki Aug 9, 2025
954e6bf
wip proofs of fixpoint preserving maps
winitzki Aug 9, 2025
0e6bf3a
wip Church-Yoneda identity
winitzki Aug 12, 2025
66974e4
proof of Church-Yoneda identity
winitzki Aug 17, 2025
8c43778
towards proof of mutually recursive fixpoints
winitzki Aug 19, 2025
29ce911
update pdf
winitzki Aug 19, 2025
56daf6f
wip
winitzki Aug 20, 2025
d4de7d5
wip
winitzki Aug 20, 2025
1201fb6
finish free semigroup discussion
winitzki Aug 21, 2025
8908026
preparing for removing the transformer notation T
winitzki Aug 21, 2025
6146f09
wip reformat chapter 14
winitzki Aug 21, 2025
ccd5b09
wip fixing chapter 14
winitzki Aug 22, 2025
a996193
wip reformatting chapter 14
winitzki Aug 24, 2025
798077a
wip reformatting chapter 14
winitzki Aug 24, 2025
2ed272f
wip reformat chapter 14
winitzki Aug 25, 2025
9a87c17
wip format chapter 14
winitzki Aug 25, 2025
9430fdb
finish formatting chapter 14
winitzki Aug 26, 2025
3425937
wip reformatting appendix A and C
winitzki Aug 27, 2025
e030601
first draft reformatting appendix
winitzki Aug 27, 2025
568e5b2
move difficult examples to comments, not clear if I can prove them ac…
winitzki Aug 30, 2025
fb5f67c
wip proof of greatest fixpoint encoding
winitzki Sep 1, 2025
9d9b452
finish proofs of greatest fixpoints
winitzki Sep 2, 2025
189013a
cut scope about least and greatest fixpoints
winitzki Sep 2, 2025
e334298
wip proof of the Church-co-Yoneda identity
winitzki Sep 2, 2025
69bf512
wip proof of Church-co-Yoneda identity
winitzki Sep 2, 2025
7a03502
finish proof of simultaneous Church encoding for greatest fixpoints
winitzki Sep 2, 2025
b81d2df
fix formatting in solutions
winitzki Sep 2, 2025
f3ca383
last change in appendix
winitzki Sep 2, 2025
f193568
add summary for chapter 8
winitzki Sep 2, 2025
ec0a025
wip summary of filterable chapter
winitzki Sep 3, 2025
d9825da
explain more about natural transformations
winitzki Sep 4, 2025
689054c
wip a new filterable construction for recursion
winitzki Sep 8, 2025
91f52e3
wip
winitzki Sep 8, 2025
f2f2d3e
wip
winitzki Sep 15, 2025
4543e5a
restore old proof of filter for List
winitzki Sep 16, 2025
483355b
wip
winitzki Sep 18, 2025
dfe8b5e
final changes for the filterable chapter and typeclass derivation exp…
winitzki Sep 18, 2025
cf9c1ff
minor update in summary
winitzki Sep 19, 2025
9b81b70
wip
winitzki Oct 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34,488 changes: 21,853 additions & 12,635 deletions sofp-src/lyx/sofp-appendices.lyx

Large diffs are not rendered by default.

890 changes: 752 additions & 138 deletions sofp-src/lyx/sofp-applicative.lyx

Large diffs are not rendered by default.

381 changes: 321 additions & 60 deletions sofp-src/lyx/sofp-curry-howard.lyx

Large diffs are not rendered by default.

1,146 changes: 865 additions & 281 deletions sofp-src/lyx/sofp-disjunctions.lyx

Large diffs are not rendered by default.

27,131 changes: 15,245 additions & 11,886 deletions sofp-src/lyx/sofp-filterable.lyx

Large diffs are not rendered by default.

28,256 changes: 17,758 additions & 10,498 deletions sofp-src/lyx/sofp-free-type.lyx

Large diffs are not rendered by default.

775 changes: 445 additions & 330 deletions sofp-src/lyx/sofp-functors.lyx

Large diffs are not rendered by default.

395 changes: 251 additions & 144 deletions sofp-src/lyx/sofp-higher-order-functions.lyx

Large diffs are not rendered by default.

198 changes: 133 additions & 65 deletions sofp-src/lyx/sofp-induction.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -19494,9 +19494,8 @@ What problems cannot be solved with these tools?
\begin_layout Standard
There is no automatic recipe for converting an arbitrary function into a
tail-recursive one.
The accumulator trick does not always work! In some cases, it is impossible
to implement tail recursion in a given recursive computation.
An example of such a computation is the
The accumulator trick does not always work! An example where it is impossible
to implement tail recursion is the
\begin_inset Quotes eld
\end_inset

Expand Down Expand Up @@ -20365,7 +20364,20 @@ def countWords(s: String): Map[String, Int] = {

\end_inset

An alternative, shorter implementation of the same function is:
An alternative, shorter implementation of the same function can be written
using the method
\begin_inset listings
inline true
status open

\begin_layout Plain Layout

groupBy
\end_layout

\end_inset

like this:
\begin_inset listings
inline false
status open
Expand All @@ -20390,7 +20402,7 @@ def countWords(s: String): Map[String, Int] =

\end_inset

The
This code creates a dictionary by a single function call to
\begin_inset listings
inline true
status open
Expand All @@ -20402,7 +20414,7 @@ groupBy

\end_inset

creates a dictionary in one function call rather than one entry at a time.
.
But the resulting dictionary contains word lists instead of word counts,
so we use
\begin_inset listings
Expand Down Expand Up @@ -21314,10 +21326,11 @@ n: Int
\end_inset

for
\begin_inset Formula $k>0$
\begin_inset Formula $k=1$
\end_inset

, where
, 2, ...
Here
\begin_inset Formula $SD(x)$
\end_inset

Expand Down Expand Up @@ -23967,7 +23980,7 @@ status open

\begin_layout Plain Layout

def revSentence(s: String): String = ???
def revSentence(text: String): String = ???
\end_layout

\begin_layout Plain Layout
Expand Down Expand Up @@ -24151,38 +24164,14 @@ noprefix "false"
\end_layout

\begin_layout Standard
Define a function
Denote
\begin_inset listings
inline true
status open

\begin_layout Plain Layout

findPalindrome: Long => Long
\end_layout

\end_inset

performing the following computation: First define
\begin_inset listings
inline true
status open

\begin_layout Plain Layout

f(n) = revDigits(n) + n
\end_layout

\end_inset

for a given integer
\begin_inset listings
inline true
status open

\begin_layout Plain Layout

n
f(n) = n + revDigits(n)
\end_layout

\end_inset
Expand Down Expand Up @@ -24214,39 +24203,38 @@ noprefix "false"
\end_inset

.
If
Using this
\begin_inset listings
inline true
status open

\begin_layout Plain Layout

f(n)
f
\end_layout

\end_inset

is a palindrome integer,
, write a function
\begin_inset listings
inline true
status open

\begin_layout Plain Layout

findPalindrome
findPalindrome(n: Long): Long
\end_layout

\end_inset

returns that integer.
Otherwise, it keeps applying the same transformation and computes
that returns the first palindrome integer found in the sequence
\begin_inset listings
inline true
status open

\begin_layout Plain Layout

f(n)
n
\end_layout

\end_inset
Expand All @@ -24258,31 +24246,29 @@ status open

\begin_layout Plain Layout

f(f(n))
f(n)
\end_layout

\end_inset

, ..., until a palindrome integer is eventually found (this is mathematically
guaranteed).
A sample test:
,
\begin_inset listings
inline false
inline true
status open

\begin_layout Plain Layout

scala> findPalindrome(10101)
\end_layout

\begin_layout Plain Layout

res0: Long = 10101
f(f(n))
\end_layout

\begin_layout Plain Layout
\end_inset

\end_layout
, etc.
(This sequence will often contain a palindrome integer, although it is
not mathematically guaranteed.) A sample test:
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

Expand Down Expand Up @@ -24418,7 +24404,7 @@ scala> skip1(List(1, 2, 3, 4, 5))

\begin_layout Plain Layout

res0: List[Int] = List((1,3), (2,4), (3,5))
res0: List[(Int, Int)] = List((1,3), (2,4), (3,5))
\end_layout

\end_inset
Expand Down Expand Up @@ -24481,7 +24467,33 @@ not
\end_inset

.

The required type signature and a sample test:
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

def largestNotThreeFiveSeven(n1: Long, n2: Long): Long = ???
\end_layout

\begin_layout Plain Layout

\end_layout

\begin_layout Plain Layout

scala> largestNotThreeFiveSeven(19, 97)
\end_layout

\begin_layout Plain Layout

res0: Long = 96L
\end_layout

\end_inset


\end_layout

\begin_layout Standard
Expand All @@ -24498,6 +24510,33 @@ not
\end_inset

with the largest sum of decimal digits.
The required type signature and a sample test:
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

def largestSum(n1: Long, n2: Long): Long = ???
\end_layout

\begin_layout Plain Layout

\end_layout

\begin_layout Plain Layout

scala> largestSum(1, 54321)
\end_layout

\begin_layout Plain Layout

res0: Long = 49999L
\end_layout

\end_inset


\end_layout

\begin_layout Standard
Expand Down Expand Up @@ -24586,7 +24625,34 @@ perfect numbers
\end_inset

is perfect.
Determine all perfect numbers up to one million.
Determine all perfect numbers up to 10 thousand.
The required type signature and a sample test:
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

def perfectNumbersUpTo(n: Int): Seq[Int] = ???
\end_layout

\begin_layout Plain Layout

\end_layout

\begin_layout Plain Layout

scala> perfectNumbersUpTo(10000)
\end_layout

\begin_layout Plain Layout

res0: Seq[Int] = List(6, 28, 496, 8128)
\end_layout

\end_inset


\end_layout

\begin_layout Subsubsection
Expand Down Expand Up @@ -26930,7 +26996,7 @@ res0: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)

\begin_layout Plain Layout

scala> iter.toList // Look at those elements again...??
scala> iter.toList // Call the function again, get another result??
\end_layout

\begin_layout Plain Layout
Expand Down Expand Up @@ -27024,7 +27090,7 @@ This situation is impossible in mathematics: if
\begin_inset Formula $f(x)+f(x)=20$
\end_inset

and obtain the correct result.
..
We could also set
\begin_inset Formula $y=f(x)$
\end_inset
Expand Down Expand Up @@ -27074,6 +27140,7 @@ status open
\begin_layout Plain Layout
After applying a pure function, we can be sure that, for instance, no hidden
values in memory have been modified.
- Not necessarily.
\end_layout

\end_inset
Expand Down Expand Up @@ -27208,7 +27275,7 @@ res0: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)

\begin_layout Plain Layout

scala> x.toList
scala> x.toList // Call the function again, get the same result.
\end_layout

\begin_layout Plain Layout
Expand Down Expand Up @@ -27302,7 +27369,7 @@ res0: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)

\begin_layout Plain Layout

scala> str.toList
scala> str.toList // Call the function again, get the same result.
\end_layout

\begin_layout Plain Layout
Expand Down Expand Up @@ -27363,7 +27430,7 @@ res0: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)

\begin_layout Plain Layout

scala> v.toList
scala> v.toList // Call the function again, get the same result.
\end_layout

\begin_layout Plain Layout
Expand Down Expand Up @@ -27741,7 +27808,8 @@ toStream
\end_inset

method.
This restores the value-based reasoning because streams behave as values:
This recovers the correctness of value-based reasoning because streams
behave as values:
\begin_inset listings
inline false
status open
Expand Down Expand Up @@ -27790,7 +27858,7 @@ res0: List[Int] = List(1, 2, 3, 4, 5, 6)

\begin_layout Plain Layout

scala> str.toList
scala> str.toList // Call the function again, get the same result.
\end_layout

\begin_layout Plain Layout
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载