mirror of
https://github.com/hmemcpy/milewski-ctfp-pdf.git
synced 2024-11-26 03:11:47 +03:00
Building with caches (#235)
* Adding Haskell minted caches * Adding Scala caches * Keeping the cache between runs (disables \minted@cleancache)
This commit is contained in:
parent
20175c7f9b
commit
8a43299f28
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,5 @@
|
||||
.vscode/
|
||||
*.fls
|
||||
_minted*
|
||||
*.fdb_latexmk
|
||||
out/*
|
||||
*.pdf
|
||||
|
@ -0,0 +1,7 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{process}\PYG{k}{:} \PYG{k+kt}{String} \PYG{o}{=\PYGZgt{}} \PYG{n+nc}{Writer}\PYG{o}{[}\PYG{k+kt}{String}\PYG{p}{,} \PYG{k+kt}{List}\PYG{o}{[}\PYG{k+kt}{String}\PYG{o}{]]} \PYG{k}{=}
|
||||
\PYG{n}{s} \PYG{k}{=\PYGZgt{}} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{import} \PYG{n+nn}{bindSyntax.\PYGZus{}}
|
||||
\PYG{n}{upCase}\PYG{o}{(}\PYG{n}{s}\PYG{o}{)} \PYG{o}{\PYGZgt{}\PYGZgt{}=} \PYG{o}{(}\PYG{n}{upStr} \PYG{k}{=\PYGZgt{}} \PYG{n}{toWords}\PYG{o}{(}\PYG{n}{upStr}\PYG{o}{))}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{factorizer}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{p}{,} \PYG{k+kt}{C}\PYG{o}{]}\PYG{k}{:} \PYG{o}{(}\PYG{k+kt}{C} \PYG{o}{=\PYGZgt{}} \PYG{k+kt}{A}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{C} \PYG{k}{=\PYGZgt{}} \PYG{n}{B}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{C} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{A}\PYG{o}{,} \PYG{n}{B}\PYG{o}{))} \PYG{k}{=}
|
||||
\PYG{n}{p} \PYG{k}{=\PYGZgt{}} \PYG{n}{q} \PYG{k}{=\PYGZgt{}} \PYG{n}{x} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{p}\PYG{o}{(}\PYG{n}{x}\PYG{o}{),} \PYG{n}{q}\PYG{o}{(}\PYG{n}{x}\PYG{o}{))}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{c+c1}{// return is a keyword in Scala}
|
||||
\PYG{k}{def} \PYG{n}{pure}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{x}\PYG{k}{:} \PYG{k+kt}{A}\PYG{o}{)}\PYG{k}{:} \PYG{k+kt}{Writer}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=} \PYG{o}{(}\PYG{n}{x}\PYG{o}{,} \PYG{l+s}{\PYGZdq{}\PYGZdq{}}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,7 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{o}{\PYGZgt{}=\PYGZgt{}[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{p}{,} \PYG{k+kt}{C}\PYG{o}{](}\PYG{n}{f}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n}{M}\PYG{o}{[}\PYG{k+kt}{B}\PYG{o}{],} \PYG{n}{g}\PYG{k}{:} \PYG{k+kt}{B} \PYG{o}{=\PYGZgt{}} \PYG{n}{M}\PYG{o}{[}\PYG{k+kt}{C}\PYG{o}{])} \PYG{k}{=}
|
||||
\PYG{n}{a} \PYG{k}{=\PYGZgt{}} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{val} \PYG{n}{mb} \PYG{k}{=} \PYG{n}{f}\PYG{o}{(}\PYG{n}{a}\PYG{o}{)}
|
||||
\PYG{o}{...}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{mu}\PYG{o}{.}\PYG{n}{compose}\PYG{o}{(}\PYG{n}{bimap}\PYG{o}{(}\PYG{n}{eta}\PYG{o}{)(}\PYG{n}{identity}\PYG{o}{[}\PYG{k+kt}{M}\PYG{o}{]))(((),} \PYG{n}{x}\PYG{o}{))} \PYG{o}{==} \PYG{n}{lambda}\PYG{o}{(((),} \PYG{n}{x}\PYG{o}{))}
|
||||
|
||||
\PYG{n}{mu}\PYG{o}{.}\PYG{n}{compose}\PYG{o}{(}\PYG{n}{bimap}\PYG{o}{(}\PYG{n}{identity}\PYG{o}{[}\PYG{k+kt}{M}\PYG{o}{])(}\PYG{n}{eta}\PYG{o}{))((}\PYG{n}{x}\PYG{o}{,} \PYG{o}{()))} \PYG{o}{==} \PYG{n}{rho}\PYG{o}{((}\PYG{n}{x}\PYG{o}{,} \PYG{o}{()))}
|
||||
\end{Verbatim}
|
@ -0,0 +1,7 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{pair}\PYG{o}{\PYGZlt{}}\PYG{k+kt}{bool}\PYG{p}{,} \PYG{n}{string}\PYG{o}{\PYGZgt{}} \PYG{n}{isOdd}\PYG{p}{(}\PYG{k+kt}{int} \PYG{n}{n}\PYG{p}{)} \PYG{p}{\PYGZob{}}
|
||||
\PYG{n}{pair}\PYG{o}{\PYGZlt{}}\PYG{k+kt}{bool}\PYG{p}{,} \PYG{n}{string}\PYG{o}{\PYGZgt{}} \PYG{n}{p1} \PYG{o}{=} \PYG{n}{isEven}\PYG{p}{(}\PYG{n}{n}\PYG{p}{);}
|
||||
\PYG{n}{pair}\PYG{o}{\PYGZlt{}}\PYG{k+kt}{bool}\PYG{p}{,} \PYG{n}{string}\PYG{o}{\PYGZgt{}} \PYG{n}{p2} \PYG{o}{=} \PYG{n}{negate}\PYG{p}{(}\PYG{n}{p1}\PYG{p}{.}\PYG{n}{first}\PYG{p}{);}
|
||||
\PYG{k}{return} \PYG{n+nf}{make\PYGZus{}pair}\PYG{p}{(}\PYG{n}{p2}\PYG{p}{.}\PYG{n}{first}\PYG{p}{,} \PYG{n}{p1}\PYG{p}{.}\PYG{n}{second} \PYG{o}{+} \PYG{n}{p2}\PYG{p}{.}\PYG{n}{second}\PYG{p}{);}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,9 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{evalZ}\PYG{k}{:} \PYG{k+kt}{Expr} \PYG{o}{=\PYGZgt{}} \PYG{n+nc}{Int} \PYG{k}{=} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n+nc}{RZero} \PYG{k}{=\PYGZgt{}} \PYG{l+m+mi}{0}
|
||||
\PYG{k}{case} \PYG{n+nc}{ROne} \PYG{k}{=\PYGZgt{}} \PYG{l+m+mi}{1}
|
||||
\PYG{k}{case} \PYG{n+nc}{RAdd}\PYG{o}{(}\PYG{n}{e1}\PYG{o}{,} \PYG{n}{e2}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{n}{evalZ}\PYG{o}{(}\PYG{n}{e1}\PYG{o}{)} \PYG{o}{+} \PYG{n}{evalZ}\PYG{o}{(}\PYG{n}{e2}\PYG{o}{)}
|
||||
\PYG{k}{case} \PYG{n+nc}{RMul}\PYG{o}{(}\PYG{n}{e1}\PYG{o}{,} \PYG{n}{e2}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{n}{evalZ}\PYG{o}{(}\PYG{n}{e1}\PYG{o}{)} \PYG{o}{*} \PYG{n}{evalZ}\PYG{o}{(}\PYG{n}{e2}\PYG{o}{)}
|
||||
\PYG{k}{case} \PYG{n+nc}{RNeg}\PYG{o}{(}\PYG{n}{e}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{o}{\PYGZhy{}}\PYG{n}{evalZ}\PYG{o}{(}\PYG{n}{e}\PYG{o}{)}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,9 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kt}{double} \PYG{n+nf}{vlen}\PYG{p}{(}\PYG{k+kt}{double} \PYG{o}{*} \PYG{n}{v}\PYG{p}{)} \PYG{p}{\PYGZob{}}
|
||||
\PYG{k+kt}{double} \PYG{n}{d} \PYG{o}{=} \PYG{l+m+mf}{0.0}\PYG{p}{;}
|
||||
\PYG{k+kt}{int} \PYG{n}{n}\PYG{p}{;}
|
||||
\PYG{k}{for} \PYG{p}{(}\PYG{n}{n} \PYG{o}{=} \PYG{l+m+mi}{0}\PYG{p}{;} \PYG{n}{n} \PYG{o}{\PYGZlt{}} \PYG{l+m+mi}{3}\PYG{p}{;} \PYG{o}{++}\PYG{n}{n}\PYG{p}{)}
|
||||
\PYG{n}{d} \PYG{o}{+=} \PYG{n}{v}\PYG{p}{[}\PYG{n}{n}\PYG{p}{]} \PYG{o}{*} \PYG{n}{v}\PYG{p}{[}\PYG{n}{n}\PYG{p}{];}
|
||||
\PYG{k}{return} \PYG{n}{sqrt}\PYG{p}{(}\PYG{n}{d}\PYG{p}{);}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{p}{(}\PYG{n}{mu} \PYG{o}{.} \PYG{n}{bimap} \PYG{n}{eta} \PYG{n}{id}\PYG{p}{)} \PYG{p}{(}\PYG{n+nb}{()}\PYG{p}{,} \PYG{n}{x}\PYG{p}{)} \PYG{o+ow}{=} \PYG{n}{lambda}\PYG{p}{(}\PYG{n+nb}{()}\PYG{p}{,} \PYG{n}{x}\PYG{p}{)}
|
||||
\PYG{p}{(}\PYG{n}{mu} \PYG{o}{.} \PYG{n}{bimap} \PYG{n}{id} \PYG{n}{eta}\PYG{p}{)} \PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n+nb}{()}\PYG{p}{)} \PYG{o+ow}{=} \PYG{n}{rho} \PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n+nb}{()}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{beta}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]}\PYG{k}{:} \PYG{k+kt}{F} \PYG{k+kt}{\PYGZti{}\PYGZgt{}} \PYG{o}{(}\PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{k+kt}{?}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{duplicate} \PYG{p}{(}\PYG{k+kt}{Cons} \PYG{n}{a} \PYG{n}{as}\PYG{p}{)} \PYG{o+ow}{=} \PYG{k+kt}{Cons} \PYG{p}{(}\PYG{k+kt}{Cons} \PYG{n}{a} \PYG{n}{as}\PYG{p}{)} \PYG{p}{(}\PYG{n}{duplicate} \PYG{n}{as}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{fmap}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{]}\PYG{k}{:} \PYG{o}{(}\PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{k+kt}{B}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{R} \PYG{k}{=\PYGZgt{}} \PYG{n}{A}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{R} \PYG{k}{=\PYGZgt{}} \PYG{n}{B}\PYG{o}{)} \PYG{k}{=}
|
||||
\PYG{n}{f} \PYG{k}{=\PYGZgt{}} \PYG{n}{g} \PYG{k}{=\PYGZgt{}} \PYG{n}{f} \PYG{n}{compose} \PYG{n}{g}
|
||||
\end{Verbatim}
|
@ -0,0 +1,6 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{template}\PYG{o}{\PYGZlt{}}\PYG{k}{class} \PYG{n+nc}{C}\PYG{p}{,} \PYG{k}{class} \PYG{n+nc}{A}\PYG{p}{,} \PYG{k}{class} \PYG{n+nc}{B}\PYG{o}{\PYGZgt{}}
|
||||
\PYG{n}{Const}\PYG{o}{\PYGZlt{}}\PYG{n}{C}\PYG{p}{,} \PYG{n}{B}\PYG{o}{\PYGZgt{}} \PYG{n}{fmap}\PYG{p}{(}\PYG{n}{std}\PYG{o}{::}\PYG{n}{function}\PYG{o}{\PYGZlt{}}\PYG{n}{B}\PYG{p}{(}\PYG{n}{A}\PYG{p}{)}\PYG{o}{\PYGZgt{}} \PYG{n}{f}\PYG{p}{,} \PYG{n}{Const}\PYG{o}{\PYGZlt{}}\PYG{n}{C}\PYG{p}{,} \PYG{n}{A}\PYG{o}{\PYGZgt{}} \PYG{n}{c}\PYG{p}{)} \PYG{p}{\PYGZob{}}
|
||||
\PYG{k}{return} \PYG{n}{Const}\PYG{o}{\PYGZlt{}}\PYG{n}{C}\PYG{p}{,} \PYG{n}{B}\PYG{o}{\PYGZgt{}}\PYG{p}{\PYGZob{}}\PYG{n}{c}\PYG{p}{.}\PYG{n}{\PYGZus{}v}\PYG{p}{\PYGZcb{};}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{alpha}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]}\PYG{k}{:} \PYG{k+kt}{F}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=\PYGZgt{}} \PYG{n}{G}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]}
|
||||
\end{Verbatim}
|
@ -0,0 +1,13 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{unit}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{a}\PYG{k}{:} \PYG{k+kt}{A}\PYG{o}{)}\PYG{k}{:} \PYG{k+kt}{U}\PYG{o}{[}\PYG{k+kt}{F}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]]} \PYG{k}{=}
|
||||
\PYG{n}{leftAdjunct}\PYG{o}{(}\PYG{n}{a}\PYG{o}{)(}\PYG{n}{identity}\PYG{o}{)}
|
||||
|
||||
\PYG{k}{def} \PYG{n}{counit}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{a}\PYG{k}{:} \PYG{k+kt}{F}\PYG{o}{[}\PYG{k+kt}{U}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]])}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=}
|
||||
\PYG{n}{rightAdjunct}\PYG{o}{(}\PYG{n}{a}\PYG{o}{)(}\PYG{n}{identity}\PYG{o}{)}
|
||||
|
||||
\PYG{k}{def} \PYG{n}{leftAdjunct}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{](}\PYG{n}{a}\PYG{k}{:} \PYG{k+kt}{A}\PYG{o}{)(}\PYG{n}{f}\PYG{k}{:} \PYG{k+kt}{F}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=\PYGZgt{}} \PYG{n}{B}\PYG{o}{)}\PYG{k}{:} \PYG{k+kt}{U}\PYG{o}{[}\PYG{k+kt}{B}\PYG{o}{]} \PYG{k}{=}
|
||||
\PYG{n}{U}\PYG{o}{.}\PYG{n}{map}\PYG{o}{(}\PYG{n}{unit}\PYG{o}{(}\PYG{n}{a}\PYG{o}{))(}\PYG{n}{f}\PYG{o}{)}
|
||||
|
||||
\PYG{k}{def} \PYG{n}{rightAdjunct}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{](}\PYG{n}{a}\PYG{k}{:} \PYG{k+kt}{F}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{])(}\PYG{n}{f}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n}{U}\PYG{o}{[}\PYG{k+kt}{B}\PYG{o}{])}\PYG{k}{:} \PYG{k+kt}{B} \PYG{o}{=}
|
||||
\PYG{n}{counit}\PYG{o}{(}\PYG{n}{F}\PYG{o}{.}\PYG{n}{map}\PYG{o}{(}\PYG{n}{a}\PYG{o}{)(}\PYG{n}{f}\PYG{o}{))}
|
||||
\end{Verbatim}
|
@ -0,0 +1,6 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{p}{(}\PYG{o}{=\PYGZgt{}=}\PYG{p}{)} \PYG{o+ow}{::} \PYG{p}{(}\PYG{k+kt}{Product} \PYG{n}{e} \PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{b}\PYG{p}{)} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{p}{(}\PYG{k+kt}{Product} \PYG{n}{e} \PYG{n}{b} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{c}\PYG{p}{)} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{p}{(}\PYG{k+kt}{Product} \PYG{n}{e} \PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{c}\PYG{p}{)}
|
||||
\PYG{n+nf}{f} \PYG{o}{=\PYGZgt{}=} \PYG{n}{g} \PYG{o+ow}{=} \PYG{n+nf}{\PYGZbs{}}\PYG{p}{(}\PYG{k+kt}{Prod} \PYG{n}{e} \PYG{n}{a}\PYG{p}{)} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kr}{let} \PYG{n}{b} \PYG{o+ow}{=} \PYG{n}{f} \PYG{p}{(}\PYG{k+kt}{Prod} \PYG{n}{e} \PYG{n}{a}\PYG{p}{)}
|
||||
\PYG{n}{c} \PYG{o+ow}{=} \PYG{n}{g} \PYG{p}{(}\PYG{k+kt}{Prod} \PYG{n}{e} \PYG{n}{b}\PYG{p}{)}
|
||||
\PYG{k+kr}{in} \PYG{n}{c}
|
||||
\end{Verbatim}
|
@ -0,0 +1,6 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{foldr}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]}\PYG{k}{:} \PYG{o}{(}\PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n}{A}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{n}{A} \PYG{k}{=\PYGZgt{}} \PYG{n+nc}{List}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=\PYGZgt{}} \PYG{n}{A} \PYG{k}{=}
|
||||
\PYG{n}{f} \PYG{k}{=\PYGZgt{}} \PYG{n}{z} \PYG{k}{=\PYGZgt{}} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n}{x} \PYG{o}{::} \PYG{n+nc}{Nil} \PYG{k}{=\PYGZgt{}} \PYG{n}{f}\PYG{o}{(}\PYG{n}{x}\PYG{o}{)(}\PYG{n}{z}\PYG{o}{)}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,9 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{auto} \PYG{k}{const} \PYG{n}{compose} \PYG{o}{=} \PYG{p}{[](}\PYG{k}{auto} \PYG{n}{m1}\PYG{p}{,} \PYG{k}{auto} \PYG{n}{m2}\PYG{p}{)} \PYG{p}{\PYGZob{}}
|
||||
\PYG{k}{return} \PYG{p}{[}\PYG{n}{m1}\PYG{p}{,} \PYG{n}{m2}\PYG{p}{](}\PYG{k}{auto} \PYG{n}{x}\PYG{p}{)} \PYG{p}{\PYGZob{}}
|
||||
\PYG{k}{auto} \PYG{n}{p1} \PYG{o}{=} \PYG{n}{m1}\PYG{p}{(}\PYG{n}{x}\PYG{p}{);}
|
||||
\PYG{k}{auto} \PYG{n}{p2} \PYG{o}{=} \PYG{n}{m2}\PYG{p}{(}\PYG{n}{p1}\PYG{p}{.}\PYG{n}{first}\PYG{p}{);}
|
||||
\PYG{k}{return} \PYG{n+nf}{make\PYGZus{}pair}\PYG{p}{(}\PYG{n}{p2}\PYG{p}{.}\PYG{n}{first}\PYG{p}{,} \PYG{n}{p1}\PYG{p}{.}\PYG{n}{second} \PYG{o}{+} \PYG{n}{p2}\PYG{p}{.}\PYG{n}{second}\PYG{p}{);}
|
||||
\PYG{p}{\PYGZcb{};}
|
||||
\PYG{p}{\PYGZcb{};}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{type} \PYG{k+kt}{IO}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=} \PYG{n+nc}{RealWorld} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{A}\PYG{o}{,} \PYG{n+nc}{RealWorld}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,6 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{duplicateS}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{wa}\PYG{k}{:} \PYG{k+kt}{Stream}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{])}\PYG{k}{:} \PYG{k+kt}{Stream}\PYG{o}{[}\PYG{k+kt}{Stream}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]]} \PYG{k}{=} \PYG{n}{wa} \PYG{k}{match} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n}{s} \PYG{k}{@} \PYG{n+nc}{Stream}\PYG{o}{(}\PYG{n}{a}\PYG{o}{,} \PYG{n}{as}\PYG{o}{)} \PYG{k}{=\PYGZgt{}}
|
||||
\PYG{n+nc}{Stream}\PYG{o}{(()} \PYG{k}{=\PYGZgt{}} \PYG{n}{s}\PYG{o}{,} \PYG{o}{()} \PYG{k}{=\PYGZgt{}} \PYG{n}{duplicateS}\PYG{o}{(}\PYG{n}{as}\PYG{o}{()))}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nc}{Product2}\PYG{o}{[}\PYG{k+kt}{Int}\PYG{p}{,} \PYG{k+kt}{Boolean}\PYG{o}{]} \PYG{o}{\PYGZti{}} \PYG{o}{(}\PYG{n+nc}{Int}\PYG{o}{,} \PYG{n+nc}{Boolean}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{c+c1}{// just imagine that the list is infinite}
|
||||
\PYG{k}{def} \PYG{n}{primes} \PYG{k}{=}
|
||||
\PYG{n}{ana}\PYG{o}{(}\PYG{n}{era}\PYG{o}{)(}\PYG{n}{streamFFunctor}\PYG{o}{)((}\PYG{l+m+mi}{1} \PYG{n}{to} \PYG{l+m+mi}{10}\PYG{o}{).}\PYG{n}{toList}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{o}{((}\PYG{n}{A}\PYG{o}{,} \PYG{n}{B}\PYG{o}{),} \PYG{n}{C}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{data} \PYG{k+kt}{Color} \PYG{o+ow}{=} \PYG{k+kt}{Red} \PYG{o}{|} \PYG{k+kt}{Green} \PYG{o}{|} \PYG{k+kt}{Blue}
|
||||
\end{Verbatim}
|
@ -0,0 +1,6 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{sealed} \PYG{k}{trait} \PYG{n+nc}{Tree}\PYG{o}{[}\PYG{k+kt}{+A}\PYG{o}{]}
|
||||
\PYG{k}{case} \PYG{k}{class} \PYG{n+nc}{Leaf}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{a}\PYG{k}{:} \PYG{k+kt}{A}\PYG{o}{)} \PYG{k}{extends} \PYG{n+nc}{Tree}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]}
|
||||
\PYG{k}{case} \PYG{k}{class} \PYG{n+nc}{Node}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{l}\PYG{k}{:} \PYG{k+kt}{Tree}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{],} \PYG{n}{r}\PYG{k}{:} \PYG{k+kt}{Tree}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{])} \PYG{k}{extends} \PYG{n+nc}{Tree}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]}
|
||||
\PYG{c+c1}{// implicit def treeFunctor = ???}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{putStr} \PYG{o+ow}{::} \PYG{k+kt}{String} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kt}{IO} \PYG{n+nb}{()}
|
||||
\end{Verbatim}
|
@ -0,0 +1,8 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{trait} \PYG{n+nc}{Procompose}\PYG{o}{[}\PYG{k+kt}{Q}\PYG{o}{[}\PYG{k}{\PYGZus{}}\PYG{p}{,} \PYG{k}{\PYGZus{}}\PYG{o}{]}\PYG{p}{,} \PYG{k+kt}{P}\PYG{o}{[}\PYG{k}{\PYGZus{}}\PYG{p}{,} \PYG{k}{\PYGZus{}}\PYG{o}{]}\PYG{p}{,} \PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{]}
|
||||
|
||||
\PYG{k}{object} \PYG{n+nc}{Procompose}\PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{def} \PYG{n}{apply}\PYG{o}{[}\PYG{k+kt}{Q}\PYG{o}{[}\PYG{k}{\PYGZus{}}\PYG{p}{,} \PYG{k}{\PYGZus{}}\PYG{o}{]}\PYG{p}{,} \PYG{k+kt}{P}\PYG{o}{[}\PYG{k}{\PYGZus{}}\PYG{p}{,} \PYG{k}{\PYGZus{}}\PYG{o}{]}\PYG{p}{,} \PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{p}{,} \PYG{k+kt}{C}\PYG{o}{]}
|
||||
\PYG{o}{(}\PYG{n}{qac}\PYG{k}{:} \PYG{k+kt}{Q}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{C}\PYG{o}{])(}\PYG{n}{pcb}\PYG{k}{:} \PYG{k+kt}{P}\PYG{o}{[}\PYG{k+kt}{C}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{])}\PYG{k}{:} \PYG{k+kt}{Procompose}\PYG{o}{[}\PYG{k+kt}{Q}\PYG{p}{,} \PYG{k+kt}{P}\PYG{p}{,} \PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{]} \PYG{k}{=} \PYG{o}{???}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,6 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{sumAlg}\PYG{k}{:} \PYG{k+kt}{ListF}\PYG{o}{[}\PYG{k+kt}{Double}\PYG{p}{,} \PYG{k+kt}{Double}\PYG{o}{]} \PYG{k}{=\PYGZgt{}} \PYG{n+nc}{Double} \PYG{k}{=} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n+nc}{ConsF}\PYG{o}{(}\PYG{n}{e}\PYG{o}{,} \PYG{n}{s}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{n}{e} \PYG{o}{+} \PYG{n}{s}
|
||||
\PYG{k}{case} \PYG{n+nc}{NilF} \PYG{k}{=\PYGZgt{}} \PYG{l+m+mf}{0.0}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{data} \PYG{k+kt}{Procompose} \PYG{n}{q} \PYG{n}{p} \PYG{n}{a} \PYG{n}{b} \PYG{k+kr}{where}
|
||||
\PYG{k+kt}{Procompose} \PYG{o+ow}{::} \PYG{n}{q} \PYG{n}{a} \PYG{n}{c} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{p} \PYG{n}{c} \PYG{n}{b} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kt}{Procompose} \PYG{n}{q} \PYG{n}{p} \PYG{n}{a} \PYG{n}{b}
|
||||
\end{Verbatim}
|
@ -0,0 +1,11 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{implicit} \PYG{k}{def} \PYG{n}{storeComonad}\PYG{o}{[}\PYG{k+kt}{S}\PYG{o}{]} \PYG{k}{=} \PYG{k}{new} \PYG{n+nc}{Comonad}\PYG{o}{[}\PYG{k+kt}{Store}\PYG{o}{[}\PYG{k+kt}{S}\PYG{p}{,} \PYG{k+kt}{?}\PYG{o}{]]} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{def} \PYG{n}{extract}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{wa}\PYG{k}{:} \PYG{k+kt}{Store}\PYG{o}{[}\PYG{k+kt}{S}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{])}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=} \PYG{n}{wa} \PYG{k}{match} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n+nc}{Store}\PYG{o}{(}\PYG{n}{f}\PYG{o}{,} \PYG{n}{s}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{n}{f}\PYG{o}{(}\PYG{n}{s}\PYG{o}{)}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
|
||||
\PYG{k}{def} \PYG{n}{duplicate}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{wa}\PYG{k}{:} \PYG{k+kt}{Store}\PYG{o}{[}\PYG{k+kt}{S}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{])}\PYG{k}{:} \PYG{k+kt}{Store}\PYG{o}{[}\PYG{k+kt}{S}\PYG{p}{,} \PYG{k+kt}{Store}\PYG{o}{[}\PYG{k+kt}{S}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{]]} \PYG{k}{=} \PYG{n}{wa} \PYG{k}{match} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n+nc}{Store}\PYG{o}{(}\PYG{n}{f}\PYG{o}{,} \PYG{n}{s}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{n+nc}{Store}\PYG{o}{(}\PYG{n+nc}{Store}\PYG{o}{(}\PYG{n}{f}\PYG{o}{),} \PYG{n}{s}\PYG{o}{)}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{put} \PYG{o+ow}{::} \PYG{n}{s} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kt}{State} \PYG{n}{s} \PYG{n+nb}{()}
|
||||
\PYG{n+nf}{put} \PYG{n}{s\PYGZsq{}} \PYG{o+ow}{=} \PYG{k+kt}{State} \PYG{p}{(}\PYG{n+nf}{\PYGZbs{}}\PYG{n}{s} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{p}{(}\PYG{n+nb}{()}\PYG{p}{,} \PYG{n}{s\PYGZsq{}}\PYG{p}{))}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{fmap}\PYG{o}{(}\PYG{n}{f}\PYG{o}{)(}\PYG{n}{alpha}\PYG{o}{(}\PYG{n}{h}\PYG{o}{))} \PYG{o}{==} \PYG{n}{alpha}\PYG{o}{(}\PYG{n}{f} \PYG{n}{compose} \PYG{n}{h}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kt}{Maybe} \PYG{p}{[}\PYG{k+kt}{Int}\PYG{p}{]} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kt}{Maybe} \PYG{p}{[}\PYG{k+kt}{Int}\PYG{p}{]}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{dumb}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]}\PYG{k}{:} \PYG{k+kt}{Reader}\PYG{o}{[}\PYG{k+kt}{Unit}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=\PYGZgt{}} \PYG{n+nc}{Option}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n+nc}{Reader}\PYG{o}{(}\PYG{k}{\PYGZus{}}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{n+nc}{None}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{data} \PYG{k+kt}{Tree} \PYG{n}{a} \PYG{o+ow}{=} \PYG{k+kt}{Leaf} \PYG{n}{a} \PYG{o}{|} \PYG{k+kt}{Node} \PYG{p}{(}\PYG{k+kt}{Tree} \PYG{n}{a}\PYG{p}{)} \PYG{p}{(}\PYG{k+kt}{Tree} \PYG{n}{a}\PYG{p}{)}
|
||||
\PYG{k+kr}{deriving} \PYG{k+kt}{Functor}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{trait} \PYG{n+nc}{Eq}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]\PYGZob{}}
|
||||
\PYG{k}{def} \PYG{o}{===(}\PYG{n}{x}\PYG{k}{:} \PYG{k+kt}{A}\PYG{o}{,} \PYG{n}{y}\PYG{k}{:} \PYG{k+kt}{A}\PYG{o}{)}\PYG{k}{:} \PYG{k+kt}{Boolean}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{f} \PYG{o}{.} \PYG{n}{p\PYGZsq{}} \PYG{o+ow}{=} \PYG{n}{g} \PYG{o}{.} \PYG{n}{p\PYGZsq{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{helpdesk} \PYG{o+ow}{::} \PYG{k+kt}{Contact}
|
||||
\PYG{n+nf}{helpdesk} \PYG{o+ow}{=} \PYG{k+kt}{PhoneNum} \PYG{l+m+mi}{2222222}
|
||||
\end{Verbatim}
|
@ -0,0 +1,22 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{implicit} \PYG{k}{def} \PYG{n}{writerMonad}\PYG{o}{[}\PYG{k+kt}{W:} \PYG{k+kt}{Monoid}\PYG{o}{]} \PYG{k}{=} \PYG{k}{new} \PYG{n+nc}{Functor}\PYG{o}{[}\PYG{k+kt}{Writer}\PYG{o}{[}\PYG{k+kt}{W}\PYG{p}{,} \PYG{k+kt}{?}\PYG{o}{]]} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{def} \PYG{o}{\PYGZgt{}=\PYGZgt{}[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{p}{,} \PYG{k+kt}{C}\PYG{o}{](}\PYG{n}{f}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n+nc}{Writer}\PYG{o}{[}\PYG{k+kt}{W}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{],} \PYG{n}{g}\PYG{k}{:} \PYG{k+kt}{B} \PYG{o}{=\PYGZgt{}} \PYG{n+nc}{Writer}\PYG{o}{[}\PYG{k+kt}{W}\PYG{p}{,} \PYG{k+kt}{C}\PYG{o}{])} \PYG{k}{=}
|
||||
\PYG{n}{a} \PYG{k}{=\PYGZgt{}} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{val} \PYG{n+nc}{Writer}\PYG{o}{((}\PYG{n}{b}\PYG{o}{,} \PYG{n}{s1}\PYG{o}{))} \PYG{k}{=} \PYG{n}{f}\PYG{o}{(}\PYG{n}{a}\PYG{o}{)}
|
||||
\PYG{k}{val} \PYG{n+nc}{Writer}\PYG{o}{((}\PYG{n}{c}\PYG{o}{,} \PYG{n}{s2}\PYG{o}{))} \PYG{k}{=} \PYG{n}{g}\PYG{o}{(}\PYG{n}{b}\PYG{o}{)}
|
||||
\PYG{n+nc}{Writer}\PYG{o}{((}\PYG{n}{c}\PYG{o}{,} \PYG{n+nc}{Monoid}\PYG{o}{[}\PYG{k+kt}{W}\PYG{o}{].}\PYG{n}{combine}\PYG{o}{(}\PYG{n}{s1}\PYG{o}{,} \PYG{n}{s2}\PYG{o}{)))}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
|
||||
\PYG{k}{def} \PYG{n}{pure}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{a}\PYG{k}{:} \PYG{k+kt}{A}\PYG{o}{)} \PYG{k}{=}
|
||||
\PYG{n+nc}{Writer}\PYG{o}{(}\PYG{n}{a}\PYG{o}{,} \PYG{n+nc}{Monoid}\PYG{o}{[}\PYG{k+kt}{W}\PYG{o}{].}\PYG{n}{empty}\PYG{o}{)}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
|
||||
\PYG{k}{object} \PYG{n+nc}{kleisliSyntax} \PYG{o}{\PYGZob{}}
|
||||
\PYG{c+c1}{//allows us to use \PYGZgt{}=\PYGZgt{} as an infix operator}
|
||||
\PYG{k}{implicit} \PYG{k}{class} \PYG{n+nc}{MonadOps}\PYG{o}{[}\PYG{k+kt}{M}\PYG{o}{[}\PYG{k}{\PYGZus{}}\PYG{o}{]}\PYG{p}{,} \PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{](}\PYG{n}{m1}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n}{M}\PYG{o}{[}\PYG{k+kt}{B}\PYG{o}{])} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{def} \PYG{o}{\PYGZgt{}=\PYGZgt{}[}\PYG{k+kt}{C}\PYG{o}{](}\PYG{n}{m2}\PYG{k}{:} \PYG{k+kt}{B} \PYG{o}{=\PYGZgt{}} \PYG{n}{M}\PYG{o}{[}\PYG{k+kt}{C}\PYG{o}{])(}\PYG{k}{implicit} \PYG{n}{m}\PYG{k}{:} \PYG{k+kt}{Monad}\PYG{o}{[}\PYG{k+kt}{M}\PYG{o}{])}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n}{M}\PYG{o}{[}\PYG{k+kt}{C}\PYG{o}{]} \PYG{k}{=} \PYG{o}{\PYGZob{}}
|
||||
\PYG{n}{m}\PYG{o}{.\PYGZgt{}=\PYGZgt{}(}\PYG{n}{m1}\PYG{o}{,} \PYG{n}{m2}\PYG{o}{)}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{process} \PYG{o+ow}{::} \PYG{k+kt}{String} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kt}{Writer} \PYG{p}{[}\PYG{k+kt}{String}\PYG{p}{]}
|
||||
\PYG{n+nf}{process} \PYG{o+ow}{=} \PYG{n}{upCase} \PYG{o}{\PYGZgt{}=\PYGZgt{}} \PYG{n}{toWords}
|
||||
\end{Verbatim}
|
@ -0,0 +1,7 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{val} \PYG{n}{upCase}\PYG{k}{:} \PYG{k+kt}{String} \PYG{o}{=\PYGZgt{}} \PYG{n+nc}{Writer}\PYG{o}{[}\PYG{k+kt}{String}\PYG{o}{]} \PYG{k}{=}
|
||||
\PYG{n}{s} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{s}\PYG{o}{.}\PYG{n}{toUpperCase}\PYG{o}{,} \PYG{l+s}{\PYGZdq{}upCase \PYGZdq{}}\PYG{o}{)}
|
||||
|
||||
\PYG{k}{val} \PYG{n}{toWords}\PYG{k}{:} \PYG{k+kt}{String} \PYG{o}{=\PYGZgt{}} \PYG{n+nc}{Writer}\PYG{o}{[}\PYG{k+kt}{List}\PYG{o}{[}\PYG{k+kt}{String}\PYG{o}{]]} \PYG{k}{=}
|
||||
\PYG{n}{s} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{s}\PYG{o}{.}\PYG{n}{split}\PYG{o}{(}\PYG{l+s+sc}{\PYGZsq{} \PYGZsq{}}\PYG{o}{).}\PYG{n}{toList}\PYG{o}{,} \PYG{l+s}{\PYGZdq{}toWords \PYGZdq{}}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kt}{Writer} \PYG{n}{b}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{fst} \PYG{o+ow}{=} \PYG{n}{p} \PYG{o}{.} \PYG{n}{m\PYGZsq{}}
|
||||
\PYG{n+nf}{snd} \PYG{o+ow}{=} \PYG{n}{q} \PYG{o}{.} \PYG{n}{m\PYGZsq{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,12 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kt}{int} \PYG{n+nf}{square}\PYG{p}{(}\PYG{k+kt}{int} \PYG{n}{x}\PYG{p}{)} \PYG{p}{\PYGZob{}}
|
||||
\PYG{k}{return} \PYG{n}{x} \PYG{o}{*} \PYG{n}{x}\PYG{p}{;}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
|
||||
\PYG{k+kt}{int} \PYG{n+nf}{counter}\PYG{p}{()} \PYG{p}{\PYGZob{}}
|
||||
\PYG{k}{static} \PYG{k+kt}{int} \PYG{n}{c} \PYG{o}{=} \PYG{l+m+mi}{0}\PYG{p}{;}
|
||||
\PYG{k}{return} \PYG{n}{c}\PYG{o}{++}\PYG{p}{;}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
|
||||
\PYG{k+kt}{double} \PYG{n}{y} \PYG{o}{=} \PYG{n}{square}\PYG{p}{(}\PYG{n}{counter}\PYG{p}{());}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kt}{Pair} \PYG{n}{a} \PYG{o+ow}{=} \PYG{k+kt}{Pair} \PYG{n}{a} \PYG{n}{a}
|
||||
\end{Verbatim}
|
@ -0,0 +1,9 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{square}\PYG{k}{:} \PYG{k+kt}{Int} \PYG{o}{=\PYGZgt{}} \PYG{n+nc}{Int} \PYG{k}{=} \PYG{n}{x} \PYG{k}{=\PYGZgt{}} \PYG{n}{x} \PYG{o}{*} \PYG{n}{x}
|
||||
|
||||
\PYG{k}{val} \PYG{n}{mis}\PYG{k}{:} \PYG{k+kt}{Option}\PYG{o}{[}\PYG{k+kt}{List}\PYG{o}{[}\PYG{k+kt}{Int}\PYG{o}{]]} \PYG{k}{=}
|
||||
\PYG{n+nc}{Some}\PYG{o}{(}\PYG{n+nc}{Cons}\PYG{o}{(}\PYG{l+m+mi}{1}\PYG{o}{,} \PYG{n+nc}{Cons}\PYG{o}{(}\PYG{l+m+mi}{2}\PYG{o}{,} \PYG{n+nc}{Cons}\PYG{o}{(}\PYG{l+m+mi}{3}\PYG{o}{,} \PYG{n+nc}{Nil}\PYG{o}{))))}
|
||||
|
||||
\PYG{k}{val} \PYG{n}{mis2} \PYG{k}{=} \PYG{n}{optionFunctor}\PYG{o}{.}
|
||||
\PYG{n}{fmap}\PYG{o}{(}\PYG{n}{listFunctor}\PYG{o}{.}\PYG{n}{fmap}\PYG{o}{(}\PYG{n}{square}\PYG{o}{))(}\PYG{n}{mis}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{instance} \PYG{k+kt}{Functor} \PYG{p}{((}\PYG{o+ow}{\PYGZhy{}\PYGZgt{}}\PYG{p}{)} \PYG{n}{r}\PYG{p}{)} \PYG{k+kr}{where}
|
||||
\PYG{n}{fmap} \PYG{n}{f} \PYG{n}{g} \PYG{o+ow}{=} \PYG{n}{f} \PYG{o}{.} \PYG{n}{g}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{p}\PYG{k}{:} \PYG{k+kt}{Int} \PYG{o}{=\PYGZgt{}} \PYG{n+nc}{Int} \PYG{k}{=} \PYG{n}{x} \PYG{k}{=\PYGZgt{}} \PYG{n}{fst}\PYG{o}{(}\PYG{n}{m}\PYG{o}{(}\PYG{n}{x}\PYG{o}{))} \PYG{c+c1}{// == x}
|
||||
\PYG{k}{def} \PYG{n}{q}\PYG{k}{:} \PYG{k+kt}{Int} \PYG{o}{=\PYGZgt{}} \PYG{n+nc}{Boolean} \PYG{k}{=} \PYG{n}{x} \PYG{k}{=\PYGZgt{}} \PYG{n}{snd}\PYG{o}{(}\PYG{n}{m}\PYG{o}{(}\PYG{n}{x}\PYG{o}{))} \PYG{c+c1}{// == true}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{p}{(}\PYG{n}{mu} \PYG{o}{.} \PYG{n}{bimap} \PYG{n}{mu} \PYG{n}{id}\PYG{p}{)((}\PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{),} \PYG{n}{z}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{type} \PYG{k+kt}{ProdP} \PYG{n}{p} \PYG{o+ow}{=} \PYG{n}{forall} \PYG{n}{a} \PYG{n}{b}\PYG{o}{.} \PYG{p}{(}\PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{b}\PYG{p}{)} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{p} \PYG{n}{a} \PYG{n}{b}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{alpha} \PYG{o+ow}{::} \PYG{n}{forall} \PYG{n}{x}\PYG{o}{.} \PYG{p}{(}\PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{x}\PYG{p}{)} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kt}{F} \PYG{n}{x}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{f} \PYG{n}{compose} \PYG{n}{p} \PYG{o}{==} \PYG{n}{g} \PYG{n}{compose} \PYG{n}{p}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{p}{(}\PYG{n}{s}\PYG{p}{,} \PYG{n}{s} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{a}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,6 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{movingAvg}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{n}\PYG{k}{:} \PYG{k+kt}{Int}\PYG{o}{)(}\PYG{n}{stm}\PYG{k}{:} \PYG{k+kt}{Stream}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{])}
|
||||
\PYG{o}{(}\PYG{k}{implicit} \PYG{n}{fractional}\PYG{k}{:} \PYG{k+kt}{Fractional}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{])}\PYG{k}{:} \PYG{k+kt}{Stream}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=}
|
||||
\PYG{n}{streamComonad}\PYG{o}{.}
|
||||
\PYG{n}{extend}\PYG{o}{(}\PYG{n}{average}\PYG{o}{(}\PYG{n}{n}\PYG{o}{)(}\PYG{n}{fractional}\PYG{o}{))(}\PYG{n}{stm}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{tail} \PYG{o+ow}{::} \PYG{k+kt}{Stream} \PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kt}{Stream} \PYG{n}{a}
|
||||
\PYG{n+nf}{tail} \PYG{p}{(}\PYG{k+kt}{Cons} \PYG{n}{a} \PYG{n}{as}\PYG{p}{)} \PYG{o+ow}{=} \PYG{n}{as}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{fst} \PYG{o}{.} \PYG{n}{factorizer} \PYG{n}{p} \PYG{n}{q} \PYG{o+ow}{=} \PYG{n}{p}
|
||||
\PYG{n+nf}{snd} \PYG{o}{.} \PYG{n}{factorizer} \PYG{n}{p} \PYG{n}{q} \PYG{o+ow}{=} \PYG{n}{q}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{m} \PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{k+kr}{\PYGZus{}}\PYG{p}{,} \PYG{n}{b}\PYG{p}{)} \PYG{o+ow}{=} \PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{b}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{alpha}\PYG{o}{(}\PYG{n}{identity}\PYG{o}{)}\PYG{k}{:} \PYG{k+kt}{F}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{instance} \PYG{k+kt}{Bifunctor} \PYG{k+kt}{Either} \PYG{k+kr}{where}
|
||||
\PYG{n}{bimap} \PYG{n}{f} \PYG{k+kr}{\PYGZus{}} \PYG{p}{(}\PYG{k+kt}{Left} \PYG{n}{x}\PYG{p}{)} \PYG{o+ow}{=} \PYG{k+kt}{Left} \PYG{p}{(}\PYG{n}{f} \PYG{n}{x}\PYG{p}{)}
|
||||
\PYG{n}{bimap} \PYG{k+kr}{\PYGZus{}} \PYG{n}{g} \PYG{p}{(}\PYG{k+kt}{Right} \PYG{n}{y}\PYG{p}{)} \PYG{o+ow}{=} \PYG{k+kt}{Right} \PYG{p}{(}\PYG{n}{g} \PYG{n}{y}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,6 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{class} \PYG{p}{(}\PYG{k+kt}{Functor} \PYG{n}{f}\PYG{p}{,} \PYG{k+kt}{Representable} \PYG{n}{u}\PYG{p}{)} \PYG{o+ow}{=\PYGZgt{}}
|
||||
\PYG{k+kt}{Adjunction} \PYG{n}{f} \PYG{n}{u} \PYG{o}{|} \PYG{n}{f} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{u}\PYG{p}{,} \PYG{n}{u} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{f} \PYG{k+kr}{where}
|
||||
\PYG{n}{leftAdjunct} \PYG{o+ow}{::} \PYG{p}{(}\PYG{n}{f} \PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{b}\PYG{p}{)} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{p}{(}\PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{u} \PYG{n}{b}\PYG{p}{)}
|
||||
\PYG{n}{rightAdjunct} \PYG{o+ow}{::} \PYG{p}{(}\PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{u} \PYG{n}{b}\PYG{p}{)} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{p}{(}\PYG{n}{f} \PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{b}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{length} \PYG{o+ow}{=} \PYG{n}{foldr} \PYG{p}{(}\PYG{n+nf}{\PYGZbs{}}\PYG{n}{e} \PYG{n}{n} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{n} \PYG{o}{+} \PYG{l+m+mi}{1}\PYG{p}{)} \PYG{l+m+mi}{0}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{runState}\PYG{o}{[}\PYG{k+kt}{S}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{]}\PYG{k}{:} \PYG{k+kt}{State}\PYG{o}{[}\PYG{k+kt}{S}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=\PYGZgt{}} \PYG{n}{S} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{A}\PYG{o}{,} \PYG{n}{S}\PYG{o}{)} \PYG{k}{=} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n+nc}{State}\PYG{o}{(}\PYG{n}{f}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{n}{s} \PYG{k}{=\PYGZgt{}} \PYG{n}{f}\PYG{o}{(}\PYG{n}{s}\PYG{o}{)}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{mu} \PYG{n}{compose} \PYG{n}{bimap}\PYG{o}{(}\PYG{n}{mu}\PYG{o}{)(}\PYG{n}{identity}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{fmap} \PYG{o+ow}{::} \PYG{p}{(}\PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{b}\PYG{p}{)} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{p}{(}\PYG{k+kt}{Maybe} \PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kt}{Maybe} \PYG{n}{b}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,8 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{evalZ} \PYG{o+ow}{::} \PYG{k+kt}{Algebra} \PYG{k+kt}{RingF} \PYG{k+kt}{Integer}
|
||||
\PYG{n+nf}{evalZ} \PYG{k+kt}{RZero} \PYG{o+ow}{=} \PYG{l+m+mi}{0}
|
||||
\PYG{n+nf}{evalZ} \PYG{k+kt}{ROne} \PYG{o+ow}{=} \PYG{l+m+mi}{1}
|
||||
\PYG{n+nf}{evalZ} \PYG{p}{(}\PYG{k+kt}{RAdd} \PYG{n}{m} \PYG{n}{n}\PYG{p}{)} \PYG{o+ow}{=} \PYG{n}{m} \PYG{o}{+} \PYG{n}{n}
|
||||
\PYG{n+nf}{evalZ} \PYG{p}{(}\PYG{k+kt}{RMul} \PYG{n}{m} \PYG{n}{n}\PYG{p}{)} \PYG{o+ow}{=} \PYG{n}{m} \PYG{o}{*} \PYG{n}{n}
|
||||
\PYG{n+nf}{evalZ} \PYG{p}{(}\PYG{k+kt}{RNeg} \PYG{n}{n}\PYG{p}{)} \PYG{o+ow}{=} \PYG{o}{\PYGZhy{}}\PYG{n}{n}
|
||||
\end{Verbatim}
|
@ -0,0 +1,9 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{evalZ}\PYG{k}{:} \PYG{k+kt}{Algebra}\PYG{o}{[}\PYG{k+kt}{RingF}\PYG{p}{,} \PYG{k+kt}{Int}\PYG{o}{]} \PYG{k}{=} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n+nc}{RZero} \PYG{k}{=\PYGZgt{}} \PYG{l+m+mi}{0}
|
||||
\PYG{k}{case} \PYG{n+nc}{ROne} \PYG{k}{=\PYGZgt{}} \PYG{l+m+mi}{1}
|
||||
\PYG{k}{case} \PYG{n+nc}{RAdd}\PYG{o}{(}\PYG{n}{m}\PYG{o}{,} \PYG{n}{n}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{n}{m} \PYG{o}{+} \PYG{n}{n}
|
||||
\PYG{k}{case} \PYG{n+nc}{RMul}\PYG{o}{(}\PYG{n}{m}\PYG{o}{,} \PYG{n}{n}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{n}{m} \PYG{o}{*} \PYG{n}{n}
|
||||
\PYG{k}{case} \PYG{n+nc}{RNeg}\PYG{o}{(}\PYG{n}{n}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{o}{\PYGZhy{}}\PYG{n}{n}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{template}\PYG{o}{\PYGZlt{}}\PYG{k}{class} \PYG{n+nc}{T}\PYG{o}{\PYGZgt{}}
|
||||
\PYG{k+kt}{void} \PYG{n}{unit}\PYG{p}{(}\PYG{n}{T}\PYG{p}{)} \PYG{p}{\PYGZob{}\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,12 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{template}\PYG{o}{\PYGZlt{}}\PYG{k}{class} \PYG{n+nc}{A}\PYG{p}{,} \PYG{k}{class} \PYG{n+nc}{B}\PYG{p}{,} \PYG{k}{class} \PYG{n+nc}{C}\PYG{o}{\PYGZgt{}}
|
||||
\PYG{n}{function}\PYG{o}{\PYGZlt{}}\PYG{n}{Writer}\PYG{o}{\PYGZlt{}}\PYG{n}{C}\PYG{o}{\PYGZgt{}}\PYG{p}{(}\PYG{n}{A}\PYG{p}{)}\PYG{o}{\PYGZgt{}} \PYG{n}{compose}\PYG{p}{(}\PYG{n}{function}\PYG{o}{\PYGZlt{}}\PYG{n}{Writer}\PYG{o}{\PYGZlt{}}\PYG{n}{B}\PYG{o}{\PYGZgt{}}\PYG{p}{(}\PYG{n}{A}\PYG{p}{)}\PYG{o}{\PYGZgt{}} \PYG{n}{m1}\PYG{p}{,}
|
||||
\PYG{n}{function}\PYG{o}{\PYGZlt{}}\PYG{n}{Writer}\PYG{o}{\PYGZlt{}}\PYG{n}{C}\PYG{o}{\PYGZgt{}}\PYG{p}{(}\PYG{n}{B}\PYG{p}{)}\PYG{o}{\PYGZgt{}} \PYG{n}{m2}\PYG{p}{)}
|
||||
\PYG{p}{\PYGZob{}}
|
||||
\PYG{k}{return} \PYG{p}{[}\PYG{n}{m1}\PYG{p}{,} \PYG{n}{m2}\PYG{p}{](}\PYG{n}{A} \PYG{n}{x}\PYG{p}{)} \PYG{p}{\PYGZob{}}
|
||||
\PYG{k}{auto} \PYG{n}{p1} \PYG{o}{=} \PYG{n}{m1}\PYG{p}{(}\PYG{n}{x}\PYG{p}{);}
|
||||
\PYG{k}{auto} \PYG{n}{p2} \PYG{o}{=} \PYG{n}{m2}\PYG{p}{(}\PYG{n}{p1}\PYG{p}{.}\PYG{n}{first}\PYG{p}{);}
|
||||
\PYG{k}{return} \PYG{n+nf}{make\PYGZus{}pair}\PYG{p}{(}\PYG{n}{p2}\PYG{p}{.}\PYG{n}{first}\PYG{p}{,} \PYG{n}{p1}\PYG{p}{.}\PYG{n}{second} \PYG{o}{+} \PYG{n}{p2}\PYG{p}{.}\PYG{n}{second}\PYG{p}{);}
|
||||
\PYG{p}{\PYGZcb{};}
|
||||
\PYG{p}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{val} \PYG{n}{f}\PYG{k}{:} \PYG{k+kt}{Boolean} \PYG{o}{=\PYGZgt{}} \PYG{n+nc}{Boolean} \PYG{k}{=} \PYG{n}{x} \PYG{k}{=\PYGZgt{}} \PYG{o}{???}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{set} \PYG{o+ow}{::} \PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{s} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{a}
|
||||
\PYG{n+nf}{get} \PYG{o+ow}{::} \PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{s}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{snd} \PYG{o+ow}{::} \PYG{p}{(}\PYG{n}{a}\PYG{p}{,} \PYG{n}{b}\PYG{p}{)} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{b}
|
||||
\PYG{n+nf}{snd} \PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{)} \PYG{o+ow}{=} \PYG{n}{y}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{flip}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{p}{,} \PYG{k+kt}{C}\PYG{o}{]}\PYG{k}{:} \PYG{o}{(}\PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{k+kt}{B} \PYG{o}{=\PYGZgt{}} \PYG{n}{C}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{B} \PYG{k}{=\PYGZgt{}} \PYG{n}{A} \PYG{k}{=\PYGZgt{}} \PYG{n}{C}\PYG{o}{)} \PYG{k}{=}
|
||||
\PYG{n}{f} \PYG{k}{=\PYGZgt{}} \PYG{n}{y} \PYG{k}{=\PYGZgt{}} \PYG{n}{x} \PYG{k}{=\PYGZgt{}} \PYG{n}{f}\PYG{o}{(}\PYG{n}{x}\PYG{o}{)(}\PYG{n}{y}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{coalg}\PYG{o}{(}\PYG{n}{set}\PYG{o}{(}\PYG{n}{a}\PYG{o}{)(}\PYG{n}{s}\PYG{o}{))} \PYG{o}{==} \PYG{n+nc}{Store}\PYG{o}{(}\PYG{n}{set}\PYG{o}{(}\PYG{n}{a}\PYG{o}{))(}\PYG{n}{s}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,6 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{trait} \PYG{n+nc}{Profunctor}\PYG{o}{[}\PYG{k+kt}{P}\PYG{o}{[}\PYG{k}{\PYGZus{}}\PYG{p}{,} \PYG{k}{\PYGZus{}}\PYG{o}{]]} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{def} \PYG{n}{dimap}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{p}{,} \PYG{k+kt}{C}\PYG{p}{,} \PYG{k+kt}{D}\PYG{o}{]}
|
||||
\PYG{o}{(}\PYG{n}{f}\PYG{k}{:} \PYG{k+kt}{C} \PYG{o}{=\PYGZgt{}} \PYG{n}{A}\PYG{o}{)(}\PYG{n}{g}\PYG{k}{:} \PYG{k+kt}{B} \PYG{o}{=\PYGZgt{}} \PYG{n}{D}\PYG{o}{)(}\PYG{n}{pab}\PYG{k}{:} \PYG{k+kt}{P}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{])}\PYG{k}{:} \PYG{k+kt}{P}\PYG{o}{[}\PYG{k+kt}{C}\PYG{p}{,} \PYG{k+kt}{D}\PYG{o}{]}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{return} \PYG{o+ow}{::} \PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kt}{Writer} \PYG{n}{a}
|
||||
\PYG{n+nf}{return} \PYG{n}{x} \PYG{o+ow}{=} \PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{l+s}{\PYGZdq{}\PYGZdq{}}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{k+kt}{Store} \PYG{n}{s} \PYG{n}{a}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{sealed} \PYG{k}{trait} \PYG{n+nc}{Fix}\PYG{o}{[}\PYG{k+kt}{F}\PYG{o}{[}\PYG{k}{\PYGZus{}}\PYG{o}{]]}
|
||||
\PYG{k}{case} \PYG{k}{class} \PYG{n+nc}{In}\PYG{o}{[}\PYG{k+kt}{F}\PYG{o}{[}\PYG{k}{\PYGZus{}}\PYG{o}{]](}\PYG{n}{f}\PYG{k}{:} \PYG{k+kt}{F}\PYG{o}{[}\PYG{k+kt}{Fix}\PYG{o}{[}\PYG{k+kt}{F}\PYG{o}{]])}
|
||||
\end{Verbatim}
|
@ -0,0 +1,8 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{implicit} \PYG{k}{val} \PYG{n}{optionFunctor} \PYG{k}{=} \PYG{k}{new} \PYG{n+nc}{Functor}\PYG{o}{[}\PYG{k+kt}{Option}\PYG{o}{]} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{def} \PYG{n}{fmap}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{](}\PYG{n}{f}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n}{B}\PYG{o}{)(}\PYG{n}{fa}\PYG{k}{:} \PYG{k+kt}{Option}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{])}\PYG{k}{:} \PYG{k+kt}{Option}\PYG{o}{[}\PYG{k+kt}{B}\PYG{o}{]} \PYG{k}{=} \PYG{n}{fa} \PYG{k}{match} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n+nc}{None} \PYG{k}{=\PYGZgt{}} \PYG{n+nc}{None}
|
||||
\PYG{k}{case} \PYG{n+nc}{Some}\PYG{o}{(}\PYG{n}{x}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{n+nc}{Some}\PYG{o}{(}\PYG{n}{f}\PYG{o}{(}\PYG{n}{x}\PYG{o}{))}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{q} \PYG{o}{==} \PYG{n}{f} \PYG{n}{compose} \PYG{n}{p}
|
||||
\PYG{n}{q} \PYG{o}{==} \PYG{n}{g} \PYG{n}{compose} \PYG{n}{p}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{data} \PYG{k+kt}{MonF} \PYG{n}{a} \PYG{o+ow}{=} \PYG{k+kt}{MEmpty} \PYG{o}{|} \PYG{k+kt}{MAppend} \PYG{n}{a} \PYG{n}{a}
|
||||
\end{Verbatim}
|
@ -0,0 +1,6 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{lambda}\PYG{o}{(}\PYG{n}{bimap}\PYG{o}{(}\PYG{n}{destroy}\PYG{o}{)(}\PYG{n}{identity}\PYG{o}{[}\PYG{k+kt}{M}\PYG{o}{])(}\PYG{n}{split}\PYG{o}{(}\PYG{n}{x}\PYG{o}{)))} \PYG{o}{==}
|
||||
\PYG{n}{lambda}\PYG{o}{(}\PYG{n}{bimap}\PYG{o}{(}\PYG{n}{destroy}\PYG{o}{)(}\PYG{n}{identity}\PYG{o}{[}\PYG{k+kt}{M}\PYG{o}{])((}\PYG{n}{f}\PYG{o}{(}\PYG{n}{x}\PYG{o}{),} \PYG{n}{g}\PYG{o}{(}\PYG{n}{x}\PYG{o}{))))} \PYG{o}{==}
|
||||
\PYG{n}{lambda}\PYG{o}{(((),} \PYG{n}{g}\PYG{o}{(}\PYG{n}{x}\PYG{o}{)))} \PYG{o}{==}
|
||||
\PYG{n}{g}\PYG{o}{(}\PYG{n}{x}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,7 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{template}\PYG{o}{\PYGZlt{}}\PYG{k}{class} \PYG{n+nc}{T}\PYG{o}{\PYGZgt{}}
|
||||
\PYG{k}{struct} \PYG{n+nl}{Leaf} \PYG{p}{:} \PYG{k}{public} \PYG{n}{Tree}\PYG{o}{\PYGZlt{}}\PYG{n}{T}\PYG{o}{\PYGZgt{}} \PYG{p}{\PYGZob{}}
|
||||
\PYG{n}{T} \PYG{n}{\PYGZus{}label}\PYG{p}{;}
|
||||
\PYG{n}{Leaf}\PYG{p}{(}\PYG{n}{T} \PYG{n}{l}\PYG{p}{)} \PYG{o}{:} \PYG{n}{\PYGZus{}label}\PYG{p}{(}\PYG{n}{l}\PYG{p}{)} \PYG{p}{\PYGZob{}\PYGZcb{}}
|
||||
\PYG{p}{\PYGZcb{};}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{instance} \PYG{k+kt}{Monad} \PYG{p}{(}\PYG{k+kt}{Reader} \PYG{n}{e}\PYG{p}{)} \PYG{k+kr}{where}
|
||||
\PYG{n}{ra} \PYG{o}{\PYGZgt{}\PYGZgt{}=} \PYG{n}{k} \PYG{o+ow}{=} \PYG{k+kt}{Reader} \PYG{p}{(}\PYG{n+nf}{\PYGZbs{}}\PYG{n}{e} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{runReader} \PYG{p}{(}\PYG{n}{k} \PYG{p}{(}\PYG{n}{runReader} \PYG{n}{ra} \PYG{n}{e}\PYG{p}{))} \PYG{n}{e}\PYG{p}{)}
|
||||
\PYG{n}{return} \PYG{n}{x} \PYG{o+ow}{=} \PYG{k+kt}{Reader} \PYG{p}{(}\PYG{n+nf}{\PYGZbs{}}\PYG{n}{e} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{x}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,6 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{implicit} \PYG{k}{def} \PYG{n}{readerFunctor}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=} \PYG{k}{new} \PYG{n+nc}{Functor}\PYG{o}{[}\PYG{k+kt}{Reader}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{?}\PYG{o}{]]} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{def} \PYG{n}{fmap}\PYG{o}{[}\PYG{k+kt}{X}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{](}\PYG{n}{f}\PYG{k}{:} \PYG{k+kt}{X} \PYG{o}{=\PYGZgt{}} \PYG{n}{B}\PYG{o}{)(}\PYG{n}{h}\PYG{k}{:} \PYG{k+kt}{Reader}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{X}\PYG{o}{])}\PYG{k}{:} \PYG{k+kt}{Reader}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{]} \PYG{k}{=}
|
||||
\PYG{n}{f} \PYG{n}{compose} \PYG{n}{h}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{case} \PYG{k}{class} \PYG{n+nc}{State}\PYG{o}{[}\PYG{k+kt}{S}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{run}\PYG{k}{:} \PYG{k+kt}{S} \PYG{o}{=\PYGZgt{}} \PYG{o}{(}\PYG{n}{A}\PYG{o}{,} \PYG{n}{S}\PYG{o}{))}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]} \PYG{o}{++} \PYG{p}{[}\PYG{l+m+mi}{3}\PYG{p}{]} \PYG{o+ow}{=} \PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{3}\PYG{p}{]}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{fmap}\PYG{o}{(}\PYG{n}{g} \PYG{n}{compose} \PYG{n}{f}\PYG{o}{)} \PYG{o}{==} \PYG{n}{fmap}\PYG{o}{(}\PYG{n}{g}\PYG{o}{)} \PYG{n}{compose} \PYG{n}{fmap}\PYG{o}{(}\PYG{n}{f}\PYG{o}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{type} \PYG{k+kt}{Algebra}\PYG{o}{[}\PYG{k+kt}{F}\PYG{o}{[}\PYG{k}{\PYGZus{}}\PYG{o}{]}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=} \PYG{n}{F}\PYG{o}{[}\PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=\PYGZgt{}} \PYG{n}{A}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{op} \PYG{o+ow}{::} \PYG{k+kt}{Op} \PYG{k+kt}{Bool} \PYG{k+kt}{Int}
|
||||
\PYG{n+nf}{op} \PYG{o+ow}{=} \PYG{k+kt}{Op} \PYG{p}{(}\PYG{n+nf}{\PYGZbs{}}\PYG{n}{x} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{x} \PYG{o}{\PYGZgt{}} \PYG{l+m+mi}{0}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{sealed} \PYG{k}{trait} \PYG{n+nc}{Nat}
|
||||
\PYG{k}{case} \PYG{k}{object} \PYG{n+nc}{Zero} \PYG{k}{extends} \PYG{n+nc}{Nat}
|
||||
\PYG{k}{case} \PYG{k}{class} \PYG{n+nc}{Succ}\PYG{o}{(}\PYG{n}{n}\PYG{k}{:} \PYG{k+kt}{Nat}\PYG{o}{)} \PYG{k}{extends} \PYG{n+nc}{Nat}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{join} \PYG{o+ow}{::} \PYG{n}{m} \PYG{p}{(}\PYG{n}{m} \PYG{n}{a}\PYG{p}{)} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{m} \PYG{n}{a}
|
||||
\end{Verbatim}
|
@ -0,0 +1,4 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{unit}\PYG{o}{[}\PYG{k+kt}{S}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{](}\PYG{n}{a}\PYG{k}{:} \PYG{k+kt}{A}\PYG{o}{)}\PYG{k}{:} \PYG{k+kt}{Reader}\PYG{o}{[}\PYG{k+kt}{S}\PYG{p}{,} \PYG{k+kt}{Product}\PYG{o}{[}\PYG{k+kt}{S}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{]]} \PYG{k}{=}
|
||||
\PYG{n+nc}{Reader}\PYG{o}{(}\PYG{n}{s} \PYG{k}{=\PYGZgt{}} \PYG{n+nc}{Product}\PYG{o}{((}\PYG{n}{a}\PYG{o}{,} \PYG{n}{s}\PYG{o}{)))}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{type} \PYG{k+kt}{Reader} \PYG{n}{a} \PYG{n}{x} \PYG{o+ow}{=} \PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{x}
|
||||
\end{Verbatim}
|
@ -0,0 +1,7 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{n}{flatten}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{W:} \PYG{k+kt}{Monoid}\PYG{o}{](}\PYG{n}{wwa}\PYG{k}{:} \PYG{k+kt}{Writer}\PYG{o}{[}\PYG{k+kt}{W}\PYG{p}{,} \PYG{k+kt}{Writer}\PYG{o}{[}\PYG{k+kt}{W}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{]])}\PYG{k}{:} \PYG{k+kt}{Writer}\PYG{o}{[}\PYG{k+kt}{W}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=}
|
||||
\PYG{n}{wwa} \PYG{k}{match} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n+nc}{Writer}\PYG{o}{((}\PYG{n+nc}{Writer}\PYG{o}{((}\PYG{n}{a}\PYG{o}{,} \PYG{n}{w2}\PYG{o}{)),} \PYG{n}{w1}\PYG{o}{))} \PYG{k}{=\PYGZgt{}}
|
||||
\PYG{n+nc}{Writer}\PYG{o}{(}\PYG{n}{a}\PYG{o}{,} \PYG{n+nc}{Monoid}\PYG{o}{[}\PYG{k+kt}{W}\PYG{o}{].}\PYG{n}{combine}\PYG{o}{(}\PYG{n}{w1}\PYG{o}{,} \PYG{n}{w2}\PYG{o}{))}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n+nf}{fmap} \PYG{n}{f} \PYG{n}{ma} \PYG{o+ow}{=} \PYG{n}{ma} \PYG{o}{\PYGZgt{}\PYGZgt{}=} \PYG{n+nf}{\PYGZbs{}}\PYG{n}{a} \PYG{o+ow}{\PYGZhy{}\PYGZgt{}} \PYG{n}{return} \PYG{p}{(}\PYG{n}{f} \PYG{n}{a}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,9 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{def} \PYG{o}{=\PYGZgt{}=[}\PYG{k+kt}{E}\PYG{p}{,} \PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{p}{,} \PYG{k+kt}{C}\PYG{o}{]}\PYG{k}{:} \PYG{o}{(}\PYG{k+kt}{Product}\PYG{o}{[}\PYG{k+kt}{E}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{]} \PYG{o}{=\PYGZgt{}} \PYG{n}{B}\PYG{o}{)} \PYG{k}{=\PYGZgt{}} \PYG{o}{(}\PYG{n+nc}{Product}\PYG{o}{[}\PYG{k+kt}{E}\PYG{p}{,} \PYG{k+kt}{B}\PYG{o}{]} \PYG{k}{=\PYGZgt{}} \PYG{n}{C}\PYG{o}{)} \PYG{k}{=\PYGZgt{}}
|
||||
\PYG{o}{(}\PYG{n+nc}{Product}\PYG{o}{[}\PYG{k+kt}{E}\PYG{p}{,} \PYG{k+kt}{A}\PYG{o}{]} \PYG{k}{=\PYGZgt{}} \PYG{n}{C}\PYG{o}{)} \PYG{k}{=} \PYG{n}{f} \PYG{k}{=\PYGZgt{}} \PYG{n}{g} \PYG{k}{=\PYGZgt{}} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{case} \PYG{n+nc}{Product}\PYG{o}{((}\PYG{n}{e}\PYG{o}{,} \PYG{n}{a}\PYG{o}{))} \PYG{k}{=\PYGZgt{}}
|
||||
\PYG{k}{val} \PYG{n}{b} \PYG{k}{=} \PYG{n}{f}\PYG{o}{(}\PYG{n+nc}{Product}\PYG{o}{((}\PYG{n}{e}\PYG{o}{,} \PYG{n}{a}\PYG{o}{)))}
|
||||
\PYG{k}{val} \PYG{n}{c} \PYG{k}{=} \PYG{n}{g}\PYG{o}{(}\PYG{n+nc}{Product}\PYG{o}{((}\PYG{n}{e}\PYG{o}{,} \PYG{n}{b}\PYG{o}{)))}
|
||||
\PYG{n}{c}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,12 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k}{implicit} \PYG{k}{def} \PYG{n}{arrowProfunctor} \PYG{k}{=} \PYG{k}{new} \PYG{n+nc}{Profunctor}\PYG{o}{[}\PYG{k+kt}{Function1}\PYG{o}{]} \PYG{o}{\PYGZob{}}
|
||||
\PYG{k}{def} \PYG{n}{dimap}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{p}{,} \PYG{k+kt}{C}\PYG{p}{,} \PYG{k+kt}{D}\PYG{o}{](}\PYG{n}{ab}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n}{B}\PYG{o}{)(}\PYG{n}{cd}\PYG{k}{:} \PYG{k+kt}{C} \PYG{o}{=\PYGZgt{}} \PYG{n}{D}\PYG{o}{)(}\PYG{n}{bc}\PYG{k}{:} \PYG{k+kt}{B} \PYG{o}{=\PYGZgt{}} \PYG{n}{C}\PYG{o}{)}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n}{D} \PYG{k}{=}
|
||||
\PYG{n}{cd} \PYG{n}{compose} \PYG{n}{bc} \PYG{n}{compose} \PYG{n}{ab}
|
||||
|
||||
\PYG{k}{def} \PYG{n}{lmap}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{p}{,} \PYG{k+kt}{C}\PYG{o}{](}\PYG{n}{f}\PYG{k}{:} \PYG{k+kt}{C} \PYG{o}{=\PYGZgt{}} \PYG{n}{A}\PYG{o}{)(}\PYG{n}{ab}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n}{B}\PYG{o}{)}\PYG{k}{:} \PYG{k+kt}{C} \PYG{o}{=\PYGZgt{}} \PYG{n}{B} \PYG{k}{=}
|
||||
\PYG{n}{f} \PYG{n}{andThen} \PYG{n}{ab}
|
||||
|
||||
\PYG{k}{def} \PYG{n}{rmap}\PYG{o}{[}\PYG{k+kt}{A}\PYG{p}{,} \PYG{k+kt}{B}\PYG{p}{,} \PYG{k+kt}{C}\PYG{o}{](}\PYG{n}{f}\PYG{k}{:} \PYG{k+kt}{B} \PYG{o}{=\PYGZgt{}} \PYG{n}{C}\PYG{o}{)(}\PYG{n}{ab}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n}{B}\PYG{o}{)}\PYG{k}{:} \PYG{k+kt}{A} \PYG{o}{=\PYGZgt{}} \PYG{n}{C} \PYG{k}{=}
|
||||
\PYG{n}{f} \PYG{n}{compose} \PYG{n}{ab}
|
||||
\PYG{o}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,5 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{data} \PYG{k+kt}{Element} \PYG{o+ow}{=} \PYG{k+kt}{Element} \PYG{p}{\PYGZob{}} \PYG{n}{name} \PYG{o+ow}{::} \PYG{k+kt}{String}
|
||||
\PYG{p}{,} \PYG{n}{symbol} \PYG{o+ow}{::} \PYG{k+kt}{String}
|
||||
\PYG{p}{,} \PYG{n}{atomicNumber} \PYG{o+ow}{::} \PYG{k+kt}{Int} \PYG{p}{\PYGZcb{}}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{k+kr}{data} \PYG{k+kt}{List} \PYG{n}{e} \PYG{o+ow}{=} \PYG{k+kt}{Nil} \PYG{o}{|} \PYG{k+kt}{Cons} \PYG{n}{e} \PYG{p}{(}\PYG{k+kt}{List} \PYG{n}{e}\PYG{p}{)}
|
||||
\end{Verbatim}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user