\documentclass{article}
\usepackage[left=3cm,top=3cm,right=4cm,nohead,bottom=3cm]{geometry}
\input{hwhw5-macros.tex}

\title{15-814 Homework hw5}
\author{YOUR NAME HERE}

\begin{document}
\maketitle

\section{Cost Dynamics}
\begin{task} \label{task:define-evals} Define rules for $\evals{e}{c}{v}$
  covering the cost graph dynamics of products (pairing and projections). You
  may want to do this task in tandem with Task \ref{task:head-exp}, which could
  help you determine what the cost graph annotations should be. Your definition
  should also satisfy Lemma \ref{lem:cost-zero} below.

  For a refresher on evaluation dynamics, see PFPL 7.
\end{task}
\begin{sol}
\end{sol}

\begin{task}[Head Expansion] \label{task:head-exp}
  Using the definitions you gave in Task \ref{task:define-evals}, show the
  following:
  \begin{enumerate}[(a)]
  \item
    If $\evals{e'}{c'}{v}$ and $\seqsteps{e}{e'}$, then there exists $c$ with
    $\evals{e}{c}{v}$ and $\wk{c} = \wk{c'} + 1$.
  \item
    If $\evals{e'}{c'}{v}$ and $\parsteps{e}{e'}$, then there exists $c$ with
    $\evals{e}{c}{v}$ and $\dep{c} = \dep{c'} + 1$.
  \end{enumerate}
  Go by induction on the derivation of $\substeps{e}{m}{e'}$. For (a), give the
  case for \rulename{Pair-S1}. For (b), give the cases for \rulename{Pair-P1},
  \rulename{Pair-P2}, \rulename{Projl-1}, and \rulename{Projl-2}.
\end{task}
\begin{sol}
\end{sol}

\section{Continuations}
\subsection{Programming with Continuations}
\begin{task} \label{task:classics}
  Define programs with the following types. You may use $\kw{ccwf}$ in your
  definitions.
  \begin{enumerate}
    \item $\kw{lem} : \tau + \tcont{\tau}$
    \item $\kw{dne} : \tcont{\tcont{\tau}} \to \tau$
    \item $\kw{cps} : (\tau_1 \to \tau_2) \to (\tcont{\tau_1} + \tau_2)$
  \end{enumerate}
  (Notice: if we interpret these types as propositions by treating $\tcont{(-)}$
  as logical negation $\lnot(-)$, these are tautologies of classical
  propositional logic!)
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  Take $\tau = \tint$ in the previous task, and consider the following
  expression $e : \tint$ defined using your implementation of $\kw{lem}$.
  \[
    \begin{array}{r c l}
      e &\eqdef& \caseop~\kw{lem}~\{ \\
      &&\quad \inl{x} \hookrightarrow 2 * x; \\
      &&\quad \inr{c} \hookrightarrow \throw{\tint}{6}{c} \\
      &&\}
    \end{array}
  \]
  What is the result of evaluating $\evalst{\stackemp}{e}$? You don't have to
  write out the stack machine steps, but give an informal explanation of the
  evaluation process.
\end{task}
\begin{sol}
\end{sol}

\subsection{Translating Continuations}
\begin{task}
  Define translation rules for the product type $\tau_1 \times \tau_2$ (i.e.,
  for pairing and the two projections). Make sure your definitions have the
  correct types!
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  Give a translation rule for function application.  For sake of intuition, you
  may find it useful to note the following: if we expand the definition of
  $\tr{\tau_2 \to \tau_1}$ another step as $\tr{\tau_2} \to (\tr{\tau_1} \to
  \rho) \to \rho$, we see that a translated function takes an \emph{argument} of
  type $\tr{\tau_2}$ and a \emph{``return address'' continuation} which
  specifies how to continue with the result of type $\tr{\tau_1}$.
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  Give translation rules for $\letcc{\tau}{x}{e}$ and $\throw{\tau'}{e_1}{e_2}$. These are actually quite simple!
\end{task}
\begin{sol}
\end{sol}

\end{document}