-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More faithful route: native TeXmacs -> LaTeX
- Loading branch information
Showing
45 changed files
with
17,219 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
\documentclass{article} | ||
\usepackage[english]{babel} | ||
\usepackage{geometry,amsmath,hyperref,theorem} | ||
\geometry{letterpaper} | ||
|
||
%%%%%%%%%% Start TeXmacs macros | ||
\catcode`\>=\active \def>{ | ||
\fontencoding{T1}\selectfont\symbol{62}\fontencoding{\encodingdefault}} | ||
\newcommand{\tmem}[1]{{\em #1\/}} | ||
\newcommand{\tmverbatim}[1]{\text{{\ttfamily{#1}}}} | ||
{\theorembodyfont{\rmfamily\small}\newtheorem{exercise}{Exercise}} | ||
%%%%%%%%%% End TeXmacs macros | ||
|
||
\begin{document} | ||
|
||
{\class{Functional Programming}} | ||
|
||
{\title{Zippers, Reactivity, GUIs}} | ||
|
||
\begin{exercise} | ||
Introduce operators $-, /$ into the context rewriting ``pull out | ||
subexpression'' example. Remember that they are not commutative. | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Add to the {\tmem{paddle game}} example: | ||
\begin{enumerate} | ||
\item game restart, | ||
|
||
\item score keeping, | ||
|
||
\item game quitting (in more-or-less elegant way). | ||
\end{enumerate} | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Our numerical integration function roughly corresponds to the rectangle | ||
rule. Modify the rule and write a test for the accuracy of: | ||
\begin{enumerate} | ||
\item the trapezoidal rule; | ||
|
||
\item the Simpson's rule. | ||
\href{http://en.wikipedia.org/wiki/Simpson%27s_rule}{http://en.wikipedia.org/wiki/Simpson\%27s\_rule} | ||
\end{enumerate} | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Explain the recursive behavior of integration: | ||
\begin{enumerate} | ||
\item In {\tmem{paddle game}} implemented by stream processing -- | ||
\tmverbatim{Lec10b.ml}, do we look at past velocity to determine current | ||
position, at past position to determine current velocity, both, or | ||
neither? | ||
|
||
\item What is the difference between \tmverbatim{integral} and | ||
\tmverbatim{integral\_nice} in \tmverbatim{Lec10c.ml}, what happens when | ||
we replace the former with the latter in the \tmverbatim{pbal} function? | ||
How about after rewriting \tmverbatim{pbal} into pure style as in the | ||
following exercise? | ||
\end{enumerate} | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Reimplement the {\tmem{Froc}} based paddle ball example in a pure style: | ||
rewrite the \tmverbatim{pbal} function to not use \tmverbatim{notify\_e}. | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
* Our implementation of flows is a bit heavy. One alternative approach is to | ||
use continuations, as in \tmverbatim{Scala.React}. OCaml has a continuations | ||
library {\tmem{Delimcc}}; for how it can cooperate with {\tmem{Froc}}, see\\ | ||
\href{http://ambassadortothecomputers.blogspot.com/2010/08/mixing-monadic-and-direct-style-code.html}{http://ambassadortothecomputers.blogspot.com/2010/08/mixing-monadic-and-direct-style-code.html} | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Implement \tmverbatim{parallel} for flows, retaining coarse-grained | ||
implementation and using the event queue from {\tmem{Froc}} somehow (instead | ||
of introducing a new job queue). | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Add quitting, e.g. via a \tmverbatim{'q'} key press, to the {\tmem{painter}} | ||
example. Use the \tmverbatim{is\_cancelled} function. | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Our calculator example is not finished. Implement entering decimal | ||
fractions: add handling of the \tmverbatim{dots} event. | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
The {\hlkwc{Flow}} module has reader monad functions that have not been | ||
discussed on slides:\\ | ||
{\hlkwa{let }}{\hlstd{local f m }}{\hlopt{= }}{\hlkwa{fun }}{\hlstd{emit | ||
}}{\hlopt{-> }}{\hlstd{m }}{\hlopt{(}}{\hlkwa{fun }}{\hlstd{x }}{\hlopt{-> | ||
}}{\hlstd{emit }}{\hlopt{(}}{\hlstd{f x}}{\hlopt{))}}{\hlendline{}}\\ | ||
{\hlkwa{let }}{\hlstd{local{\textunderscore}opt f m }}{\hlopt{= | ||
}}{\hlkwa{fun }}{\hlstd{emit }}{\hlopt{->}}{\hlendline{}}\\ | ||
{\hlstd{ \ m }}{\hlopt{(}}{\hlkwa{fun }}{\hlstd{x }}{\hlopt{-> | ||
}}{\hlkwa{match }}{\hlstd{f x }}{\hlkwa{with }}{\hlkwd{None }}{\hlopt{-> () | ||
\textbar }}{\hlkwd{Some }}{\hlstd{y }}{\hlopt{-> }}{\hlstd{emit | ||
y}}{\hlopt{)}}{\hlendline{}}\\ | ||
{\hlkwa{val }}{\hlstd{local }}{\hlopt{: (}}{\hlstd{'a }}{\hlopt{-> | ||
}}{\hlstd{'b}}{\hlopt{) -> (}}{\hlstd{'a}}{\hlopt{, }}{\hlstd{'c}}{\hlopt{) | ||
}}{\hlstd{flow }}{\hlopt{-> (}}{\hlstd{'b}}{\hlopt{, }}{\hlstd{'c}}{\hlopt{) | ||
}}{\hlstd{flow}}{\hlendline{}}\\ | ||
{\hlkwa{val }}{\hlstd{local{\textunderscore}opt }}{\hlopt{: (}}{\hlstd{'a | ||
}}{\hlopt{-> }}{\hlstd{'b }}{\hlkwb{option}}{\hlopt{) -> | ||
(}}{\hlstd{'a}}{\hlopt{, }}{\hlstd{'c}}{\hlopt{) }}{\hlstd{flow }}{\hlopt{-> | ||
(}}{\hlstd{'b}}{\hlopt{, }}{\hlstd{'c}}{\hlopt{) | ||
}}{\hlstd{flow}}{\hlendline{}} | ||
|
||
Implement an example that uses this compositionality-increasing capability. | ||
\end{exercise} | ||
|
||
\ | ||
|
||
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
\documentclass{article} | ||
\usepackage[english]{babel} | ||
\usepackage{geometry,hyperref} | ||
\geometry{letterpaper} | ||
|
||
%%%%%%%%%% Start TeXmacs macros | ||
\newcommand{\tmem}[1]{{\em #1\/}} | ||
\newcommand{\tmemail}[1]{\\ \textit{Email:} \texttt{#1}} | ||
\newcommand{\tmhomepage}[1]{\\ \textit{Web:} \texttt{#1}} | ||
\newcommand{\tmsubtitle}[1]{\thanks{\textit{Subtitle:} #1}} | ||
%%%%%%%%%% End TeXmacs macros | ||
|
||
\begin{document} | ||
|
||
{\screens{{\tit{The Expression Problem}} | ||
|
||
\title{ | ||
The Expression Problem | ||
\tmsubtitle{Code organization, extensibility and reuse} | ||
} | ||
|
||
\author{ | ||
{\L}ukasz Stafiniak | ||
\tmemail{[email protected]} | ||
\tmhomepage{www.ii.uni.wroc.pl/\~{}lukstafi} | ||
} | ||
|
||
\maketitle | ||
\begin{itemize} | ||
\item Ralf L{\"a}mmel lectures on MSDN's Channel 9:\\ | ||
\href{http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Dr-Ralf-Laemmel-Advanced-Functional-Programming-The-Expression-Problem}{The | ||
Expression Problem}, | ||
\href{http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Dr-Ralf-Lmmel-Advanced-Functional-Programming-Type-Classes}{Haskell's | ||
Type Classes} | ||
|
||
\item The old book {\tmem{Developing Applications with Objective Caml}}:\\ | ||
\href{http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora153.html}{Comparison | ||
of Modules and Objects}, | ||
\href{http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora154.html}{Extending | ||
Components} | ||
|
||
\item The new book {\tmem{Real World OCaml}}: | ||
\href{https://realworldocaml.org/v1/en/html/objects.html}{Chapter 11: | ||
Objects}, \href{https://realworldocaml.org/v1/en/html/classes.html}{Chapter | ||
12: Classes} | ||
|
||
\item Jacques Garrigue's | ||
\href{http://www.math.nagoya-u.ac.jp/~garrigue/papers/variant-reuse.ps.gz}{Code | ||
reuse through polymorphic variants},\\ | ||
and | ||
\href{http://www.math.nagoya-u.ac.jp/~garrigue/papers/nakata-icfp2006.pdf}{Recursive | ||
Modules for Programming} with Keiko Nakata | ||
|
||
\item | ||
\href{http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec246}{Extensible | ||
variant types} | ||
|
||
\item Graham Hutton's and Erik Meijer's | ||
\href{https://www.cs.nott.ac.uk/~gmh/monparsing.pdf}{Monadic Parser | ||
Combinators} | ||
\end{itemize}}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}} | ||
|
||
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
\documentclass{article} | ||
\usepackage[english]{babel} | ||
\usepackage{geometry,amsmath,theorem} | ||
\geometry{letterpaper} | ||
|
||
%%%%%%%%%% Start TeXmacs macros | ||
\catcode`\>=\active \def>{ | ||
\fontencoding{T1}\selectfont\symbol{62}\fontencoding{\encodingdefault}} | ||
\newcommand{\tmem}[1]{{\em #1\/}} | ||
\newcommand{\tmname}[1]{\textsc{#1}} | ||
\newcommand{\tmverbatim}[1]{\text{{\ttfamily{#1}}}} | ||
{\theorembodyfont{\rmfamily\small}\newtheorem{exercise}{Exercise}} | ||
%%%%%%%%%% End TeXmacs macros | ||
|
||
\begin{document} | ||
|
||
{\class{Functional Programming}}{\tmname{{\L}ukasz Stafiniak}} | ||
|
||
{\title{The Expression Problem}} | ||
|
||
\begin{exercise} | ||
\label{ExStringOf}Implement the \tmverbatim{string\_of\_} functions or | ||
methods, covering all data cases, corresponding to the \tmverbatim{eval\_} | ||
functions in at least two examples from the lecture, including both an | ||
object-based example and a variant-based example (either standard, or | ||
polymorphic, or extensible variants). | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
\label{ExSplitFiles}Split at least one of the examples from the previous | ||
exercise into multiple files and demonstrate separate compilation. | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Can we drop the tags \tmverbatim{Lambda\_t}, \tmverbatim{Expr\_t} and | ||
\tmverbatim{LExpr\_t} used in the examples based on standard variants (file | ||
\tmverbatim{FP\_ADT.ml})? When using polymorphic variants, such tags are not | ||
needed. | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Factor-out the sub-language consisting only of variables, thus eliminating | ||
the duplication of tags \tmverbatim{VarL}, \tmverbatim{VarE} in the examples | ||
based on standard variants (file \tmverbatim{FP\_ADT.ml}). | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Come up with a scenario where the extensible variant types-based solution | ||
leads to a non-obvious or hard to locate bug. | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
* Re-implement the direct object-based solution to the expression problem | ||
(file \tmverbatim{Objects.ml}) to make it more satisfying. For example, | ||
eliminate the need for some of the \tmverbatim{rename}, \tmverbatim{apply}, | ||
\tmverbatim{compute} methods. | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Re-implement the visitor pattern-based solution to the expression problem | ||
(file \tmverbatim{Visitor.ml}) in a functional way, i.e. replace the mutable | ||
fields \tmverbatim{subst} and \tmverbatim{beta\_redex} in the | ||
\tmverbatim{eval\_lambda} class with a different solution to the problem of | ||
treating \tmverbatim{abs} and non-\tmverbatim{abs} expressions differently. | ||
|
||
* See if you can replace the reference cells \tmverbatim{result} in | ||
\tmverbatim{eval$N$} and \tmverbatim{freevars$N$} functions (for | ||
\tmverbatim{$N =$1,2,3}) with a different solution to the problem of | ||
polymorphism wrt. the type of the computed values. | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Extend the sub-language \tmverbatim{expr\_visit} with variables, and add to | ||
arguments of the evaluation constructor \tmverbatim{eval\_expr} the | ||
substitution. Handle the problem of potentially duplicate fields | ||
\tmverbatim{subst}. (One approach might be to use ideas from exercise 6.) | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Impement the following modifications to the example from the file | ||
\tmverbatim{PolyV.ml}: | ||
\begin{enumerate} | ||
\item Factor-out the sub-language of variables, around the already present | ||
\tmverbatim{var} type. | ||
|
||
\item Open the types of functions \tmverbatim{eval3}, | ||
\tmverbatim{freevars3} and other functions as required, so that explicit | ||
subtyping, e.g. in {\hlstd{eval3\enspace}}{\hlopt{[]\enspace | ||
(}}{\hlstd{test2\enspace}}{\hlopt{:>\enspace}}{\hlstd{lexpr{\textunderscore}t}}{\hlopt{)}}, | ||
is not necessary. | ||
|
||
\item Remove the double-dispatch currently in \tmverbatim{eval\_lexpr} and | ||
\tmverbatim{freevars\_lexpr}, by implementing a cascading design rather | ||
than a ``divide-and-conquer'' design. | ||
\end{enumerate} | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Streamline the solution \tmverbatim{PolyRecM.ml} by extending the language | ||
of $\lambda$-expressions with arithmetic expressions, rather than defining | ||
the sub-languages separately and then merging them. See slide on page 15 of | ||
Jacques Garrigue {\tmem{Structural Types, Recursive Modules, and the | ||
Expression Problem}}. | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Transform a parser monad, or rewrite the parser monad transformer, by adding | ||
state for the line and column numbers. | ||
|
||
* How to implement a monad transformer transformer in OCaml? | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
Implement \tmverbatim{\_of\_string} functions as parser combinators on top | ||
of the example \tmverbatim{PolyRecM.ml}. Sections 4.3 and 6.2 of | ||
{\tmem{Monadic Parser Combinators}} by Graham Hutton and Erik Meijer might | ||
be helpful. Split the result into multiple files as in Exercise | ||
\ref{ExSplitFiles} and demonstrate dynamic loading of code. | ||
\end{exercise} | ||
|
||
\begin{exercise} | ||
What are the benefits and drawbacks of our lazy-monad-plus (built on top of | ||
{\tmem{odd lazy lists}}) approach, as compared to regular monad-plus built | ||
on top of {\tmem{even lazy lists}}? To additionally illustrate your answer: | ||
\begin{enumerate} | ||
\item Rewrite the parser combinators example to use regular monad-plus and | ||
even lazy lists. | ||
|
||
\item Select one example from Lecture 8 and rewrite it using | ||
lazy-monad-plus and odd lazy lists. | ||
\end{enumerate} | ||
\end{exercise} | ||
|
||
\ | ||
|
||
\end{document} |
Oops, something went wrong.