\documentclass[11pt]{article}

\usepackage{times,mathptm}
\pagestyle{myheadings}



\parindent 0in
\setlength{\parindent}{0in}
\setlength{\parskip}{1ex}

\topmargin -0.1in \headheight\baselineskip
\textheight 8.5in         % 1in top and bottom margin
\textwidth 6.5in        % 1in left and right margin
\oddsidemargin 0in
\evensidemargin 0in




\usepackage{amsmath}
\usepackage{amssymb}


% \setlength{\itemsep}{0pt}

\markright{\footnotesize CS 451 Programming Paradigms, Spring 2001}

\begin{document}

\section*{Addendum to Project 1: Programming in ML --- main project due Wednesday 28 March, tasks described here due Monday 2 April}


\subsection*{A library of $\lambda$-terms}

$\textsf{\textbf{I}} \triangleq \lambda x. x$ \hfill
$\textsf{\textbf{K}} \triangleq \lambda xy. x$  \hfill
$\textsf{\textbf{S}} \triangleq \lambda fgx. (f x) (g x)$  \hfill
$\textsf{\textbf{B}} \triangleq \lambda fgx. f (g x)$  \hfill
$\textsf{\textbf{C}} \triangleq \lambda fgx. f x g$

$\omega \triangleq \lambda x. x x$ \hfill
$\Omega \triangleq \omega \omega$ \hfill
$\textsf{\textbf{Y}} \triangleq \lambda f. (\lambda x. f (x \: x))(\lambda x. f (x \: x))$

$\textsf{\textbf{true}} \triangleq \lambda xy. x$ \hfill
$\textsf{\textbf{false}} \triangleq \lambda xy. y$ \hfill
$\textsf{\textbf{not}} \triangleq \lambda t. t \ \textsf{\textbf{false}} \ \textsf{\textbf{true}}$ \hfill
$\textsf{\textbf{cond}} \triangleq \lambda e e_1 e_2 . e e_1 e_2$

$\textsf{\textbf{pair}} \triangleq \lambda e_1 e_2 f. f e_1 e_2$ \hfill
$\textsf{\textbf{fst}} \triangleq \lambda p. p \ \textsf{\textbf{true}}$ \hfill
$\textsf{\textbf{snd}} \triangleq \lambda p. p \ \textsf{\textbf{false}}$

$\textsf{\textbf{0}} \triangleq \lambda fx. x$ \hfill
$\textsf{\textbf{1}} \triangleq \lambda fx. f x$ \hfill
$\textsf{\textbf{2}} \triangleq \lambda fx. f (f x)$ \hfill
$\textsf{\textbf{succ}} \triangleq \lambda nfx. n f (f x)$ \hfill
$\textsf{\textbf{add}} \triangleq \lambda mnfx. m f (n f x)$ \hfill
$\textsf{\textbf{iszero}} \triangleq \lambda n. n (\lambda x. \textsf{\textbf{false}}) \textsf{\textbf{true}}$ \hfill
$\textsf{\textbf{prefn}} \triangleq \lambda fp. \textsf{\textbf{pair}} \ \textsf{\textbf{false}} (\textsf{\textbf{cond}} (\textsf{\textbf{fst}} \ p) (\textsf{\textbf{snd}} \ p) (f (\textsf{\textbf{snd}} p)))$ \hfill
$\textsf{\textbf{pred}} \triangleq \lambda nfx. \textsf{\textbf{snd}} (n (\textsf{\textbf{prefn}} \ f) (\textsf{\textbf{pair}} \ \textsf{\textbf{true}} \ x))$ \hfill

$\textsf{\textbf{cons}} \triangleq \lambda hts.s h t$ \hfill
$\textsf{\textbf{hd}} \triangleq \lambda L. L \ \textsf{\textbf{true}}$ \hfill
$\textsf{\textbf{tl}} \triangleq \lambda L. L \ \textsf{\textbf{false}}$ \hfill
$\textsf{\textbf{nil}} \triangleq \lambda x. \textsf{\textbf{true}}$ \hfill
$\textsf{\textbf{isempty}} \triangleq \lambda L. L (\lambda ht. \textsf{\textbf{false}})$





\subsection*{Normal forms of some $\lambda$-terms}

$\textsf{\textbf{S}} \textsf{\textbf{K}} \textsf{\textbf{K}} 
\twoheadrightarrow 
\lambda x . x$
 \hfill
$\textsf{\textbf{K}} (\textsf{\textbf{S}} \textsf{\textbf{I}} \textsf{\textbf{I}})
\twoheadrightarrow 
\lambda a b . b b$
 \hfill
$\textsf{\textbf{S}} (\textsf{\textbf{S}} (\textsf{\textbf{K}}\textsf{\textbf{S}})(\textsf{\textbf{K}}\textsf{\textbf{I}})) (\textsf{\textbf{K}}\textsf{\textbf{I}})
\twoheadrightarrow 
\lambda a b . b b$
 \hfill
$\textsf{\textbf{S}}\textsf{\textbf{S}}\textsf{\textbf{S}}\textsf{\textbf{S}}\textsf{\textbf{S}}\textsf{\textbf{S}}\textsf{\textbf{S}}
\twoheadrightarrow 
\lambda a b . ( a b (a b (a b \lambda c. a c (b c))))$





\subsection*{Additional tasks}

\begin{enumerate}


\item (30 pts. extra credit)

Implement $\delta$-conversion rules for arithmetic, and input/output
syntax for numbers. Extend the parser to recognize decimal integers
and the common arithmetic operators +, -, etc. The operators do not
need to be infix.
You may rely on the underlying SML type \textit{int}.

\item (30 pts. extra credit)

Implement $\delta$-conversion rules for a primitive list type with
constructors \textsf{\textbf{cons}} and \textsf{\textbf{nil}}
that can be used to build lists of $\lambda$-terms. 
Extend the parser to recognize \textsf{\textbf{cons}} and \textsf{\textbf{nil}},
and extend the pretty-printer to print them.

\item (30 pts. extra credit)

Extend the parser  to recognize
and the pretty-printer to print infix arithmetic operators,
the infix \textsf{\textbf{cons}} (written \textsf{\textbf{::}}), and
the list notation \textsf{\textbf{[  , ]}}.




\end{enumerate}

Any of the extensions you do should be written modularly, so that they can be
included or excluded at will. This will allow you, for instance,
to compare the efficiency
of arithmetic using Church's $\lambda$-terms and 
arithmetic using built-in primitives.




\subsection*{Grading}

Total number of points available on this project is now 230. Full credit
remains equivalent to 100 points.

\end{document}

