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

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

\begin{document}
\maketitle

\section{Modernized Algol}
\subsection{References for Mutable Data Structures}
\begin{task}
  Give a definition of the type \verb|tree*| in \langma\ with recursive types and a
  type \verb|int|, as presented above (without making any improvements).
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  We previously concluded that trees are better encoded using sum types. For
  each of the following specifications, define a type $\ttree{\tau}$ of mutable
  trees with the described behavior. In each case, an element of a tree type
  should consist either of a leaf with a value of type $\tau$ or of two
  subtrees.
  \begin{enumerate}[(a)]
  \item A mutable tree can be changed to a leaf (by supplying a value of type
    $\tau$) or to a node (by supplying a new pair of mutable subtrees).
  \item A mutable tree is permanently either a leaf or a node with two
    subtrees. Leaves cannot be updated. However, a node can be mutated by
    modifying one of the two subtrees.
  \item A mutable tree can only be updated by providing a whole new tree; its
    subparts cannot be modified in isolation.
  \end{enumerate}
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  For the encoding of $\ttree{\tau}$ you defined in Task 2(a), define a
  function
  \[
    \kw{tmap} : (\tau \to \tau) \to \ttree{\tau} \to \tcmd{\tunit}
  \]
  so that $\kw{tmap}\; f\; t$ applies the function $f$ to each leaf in $t$ in
  place. For the sake of convenience, you may use $\fixop$, as well as any
  derived operators (such as $\mdo{e}$ and $m_1;m_2$) that we have discussed in
  class. You don't have to consider the behavior on $\kw{tmap}$ on circular
  trees.
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  For each of the following alternate type specifications below, explain
  informally whether it is possible to define a term of said type with the same
  or similar behavior as in the previous task. If it is possible, describe any
  difference in functionality between the two.
  \begin{enumerate}[(a)]
    \item $(\tau \to \tau) \to \ttree{\tau} \to \tunit$
    \item $\tcmd{(\tau \to \tau)} \to \ttree{\tau} \to \tcmd{\tunit}$
    \item $(\tau \to \tcmd{\tau}) \to \ttree{\tau} \to \tcmd{\tunit}$
    \item $(\tau \to \tau) \to \tcmd{(\ttree{\tau} \to \tunit)}$
  \end{enumerate}
\end{task}
\begin{sol}
\end{sol}

\subsection{Exceptions}
\begin{task}
  Give control stack dynamics rules for $\bndop$. (Remember to handle cases
  involving exceptions!)
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  We can also add exceptions to \langma\ with \emph{scoped} assignables. In this
  setup, \rulename{Dcl-I} is different: rather than reducing a declaration
  $\mdcl{v}{a}{m}$ by adding $\memmap{a}{v}$ to the memory and deleting the
  declaration, we push the declaration onto the stack and continue as $m$. As a
  result, we can do away with the memory completely and instead maintain the
  values of assignables on the control stack. In this version, we'll use states
  $k \sexec m$, $k \sret v$, and $k \sexn v$, each in a signature
  $\sstate{\Sg}{-}$ (but without a memory).
  \[
  \infer[\rulename{Decl-I}]
    {\sstate{\Sg}{k \sexec_\Sg \mdcl{e}{a}{m}}
      \step \sstate{\Sg,a \shas \tau}{k;\mdcl{v}{a}{-} \sexec_\Sg m}}
    {\vals{e}{\Sg}{v}}
  \]
  \begin{enumerate}[(a)]
  \item What restriction to the exception setup is necessary to ensure type
    safety if we use scoped assignables? Give an example of how type safety can
    fail otherwise.
  \item Finish the set of dynamics rules for $\mdcl{v}{a}{m}$ for this setup,
    and give rules for $\mget{a}$ and $\mset{a}{e}$. (You may find it useful to
    define auxiliary judgments to search for and update assignable values in the
    control stack.)
  \item For which of the rules you gave in (b) is the restriction you described
    in (a) necessary for preservation? Why?
  \end{enumerate}
\end{task}
\begin{sol}
\end{sol}

\section{Exceptions from Fluid Binding}
\begin{task}
  Using fluid binding and continuations (with $\letccop$ and $\throwop$), define
  encodings of the expressions $\eraise{\tau}{e}$ and
  $\etry{e_1}{x}{e_2}$. Assume a type $\texn$ is given; you choose
  $\tfluid$. You can also assume that the fluid cell is not being used for other
  purposes. If an exception reaches the toplevel, it should result in an
  $\kw{err}$ state.
\end{task}
\begin{sol}
\end{sol}

\section{Dynamic Classification for Existentials}
\begin{task}
  Define $\packop$ and $\openop$ for this encoding, assuming that $t.\tau$ is a
  positive type operator.
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  The condition that $t.\tau$ is positive is sufficient, but not necessary. Give
  definitions of $\packop$ and $\openop$ for the operator $t.t \times (t \to
  \tnat)$, in which the first occurence of $t$ is positive but the second is
  negative.
\end{task}
\begin{sol}
\end{sol}

\begin{task}
  In class, we discussed the dual concepts of \emph{integrity} and
  \emph{confidentiality} with respect to dynamic classification. The integrity
  of classified values is determined by which parties have access to the
  constructor $\inop[a]$, while confidentiality concerns access to the
  destructor $\isinop[a]$. Describe the role these play in your answers to Tasks
  8 and 9.
\end{task}
\begin{sol}
\end{sol}

\end{document}