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

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

\begin{document}
\maketitle

\section{Representation Independence and the Dispatch Matrix}
\begin{task}
  Define an isomorphism between the types $\tmv$ and $\tcv$ by giving
  terms $f : \tmv \to \tcv$ and $g : \tcv \to \tmv$. You are not
  required to prove that the two are mutually inverse (yet).
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  For the functions $f$ and $g$ you defined in Task 1, show that
  $g(f(e)) \sim_{\tmv} e$ for any $e : \tmv$. Assume an eager
  dynamics. You may use parametricity and the fact that $\sim$ is
  closed under forward and converse evaluation.
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  Show that $m_1 \sim_{\texists{\vobj}{\tabs}} m_2$. As part of this
  proof, you will have to show that a particular relationship holds
  between (a) $\kw{new}_1$ and $\kw{new}_2$ and (b) $\kw{send}_1$ and
  $\kw{send}_2$; you need only give the proof for (a). Also, you are
  not required to show that any relations you define are admissible,
  and you may use the fact that the language is terminating without
  proof.
\end{task}
\begin{sol}
\end{sol}

\section{Self-Reference and Dynamic Dispatch}
\begin{task}
  For this task, you'll implement an (admittedly contrived) system
  where objects are used to represent booleans. Your definition should
  support the following two classes:
  \begin{itemize}
    \item The class $\kw{one}$ with $\tau^{\kw{one}} = \tunit +
      \tunit$, which represents true as $\einl{\triv}$ and false as
      $\einr{\triv}$.
    \item The class $\kw{two}$ with $\tau^{\kw{two}} = \tnat$, which
      represents false as $\zero$ and true as any successor $\suc{e}$.
  \end{itemize}
  and the following two methods:
  \begin{itemize}
    \item The method $\kw{if}$ with $\rho_\kw{if} = \tforall{t}{t \hto
      t \hto t}$, which, when given a type and two arguments of that
      type, returns its first argument if the boolean is true and its
      second if the boolean is false.
    \item The method $\kw{not}$ with $\rho_\kw{not} = \vobj$, which
      returns a boolean's negation.
  \end{itemize}
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  \correction{11/2/15}{Changed $\texists{\vobj}{\tobj}$ to $\texists{\vobj}{\tabs}$.}

  Suppose you are given a self-referential dispatch matrix $\edm :
  \tdm'$. Give an implementation of the abstract dispatch matrix type
  $\texists{\vobj}{\tabs}$. (You will probably want to separate your
  definition into a few helper terms.) In order to deal with
  self-reference, use the type $\tself{\tau}$ we described in class
  (and which is covered in PFPL 20.3), which is definable using
  recursive types. Do not use $\fixop$.
\end{task}
\begin{sol}
\end{sol}

\section{Dynamic Types with Refinements}
\begin{task}
  For the following terms, give the strongest possible refinement
  derivable with the rules above or determine that none exists. If
  there is a derivation, describe it, and if not, explain why.
  \begin{enumerate}
    \item $\enumc{(\ifz{e}{\enum{\zero}}{x}{\enum{x}})}$, assuming
      $\inrefn{e}{\tnat}{\rtop{\tnat}}$,
    \item $\ifz{e}{\enum{\zero}}{\_}{\efun{(\lam{x}{\tdyn}{x})}}$,
      assuming $\inrefn{e}{\tnat}{\rtop{\tnat}}$,
    \item
      $\enumc{(\ifz{e}{\enum{\zero}}{\_}{\efun{(\lam{x}{\tdyn}{x})}})}$,
      assuming $\inrefn{e}{\tnat}{\rtop{\tnat}}$,
    \item $\efix{x}{\tnat}{x}$.
  \end{enumerate}
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  Although the expression
  $\ifz{\suc{\zero}}{\efun{(\lam{x}{\tdyn}{x})}}{x}{\enum{x}}$ clearly
  evaluates to $\rnum{\zero}$, it is not possible to give it the
  refinement $\rnum{\rtop{\tnat}}$, because the refinement system
  fails to notice that the first argument to $\ifzop$ is a
  successor. We can solve this by introducing new refinements $\zero
  \refines \tnat$ and $\suc{\phi} \refines \tnat$ (where $\phi
  \refines \tnat$), which are satisfied by zero and successors
  respectively. (This is quite analogous to the case of $\tdyn$ when
  we consider that both $\tdyn \approx \tnat + (\tdyn \hto \tdyn)$ and
  $\tnat \approx \tunit + \tnat$ are essentially sum types!) Define
  refinement satisfaction rules for $\zero$ and $\suc{\phi}$ such that
\[
\inrefn{\ifz{\suc{\zero}}{\efun{(\lam{x}{\tdyn}{x})}}{x}{\enum{x}}}{\tdyn}{\rnum{\zero}}
\]
is derivable.

\correction{11/2/15}{Note: by ``refinement satisfaction rules for $\zero$ and $\suc{\phi}$'' we mean not just rules involving $\zero$ and $\suc{e}$ but also rules for $\ifzop$.}
\end{task}
\begin{sol}
\end{sol}

\end{document}