Index: doc/generic_types/generic_types.tex
===================================================================
--- doc/generic_types/generic_types.tex	(revision a53e10a137167a159802005de2655dfb126bf585)
+++ doc/generic_types/generic_types.tex	(revision 1c2c25378f0dba8478443afe179a6e47254093ed)
@@ -1,8 +1,57 @@
+% take of review (for line numbers) and anonymous (for anonymization) on submission
 \documentclass[format=acmlarge, anonymous, review]{acmart}
 
+\usepackage{listings}	% For code listings
+
+% Useful macros
+\newcommand{\CFA}{C$\mathbf\forall$} % Cforall symbolic name
+\newcommand{\CC}{\rm C\kern-.1em\hbox{+\kern-.25em+}} % C++ symbolic name
+\newcommand{\CCeleven}{\rm C\kern-.1em\hbox{+\kern-.25em+}11} % C++11 symbolic name
+\newcommand{\CCfourteen}{\rm C\kern-.1em\hbox{+\kern-.25em+}14} % C++14 symbolic name
+\newcommand{\CCseventeen}{\rm C\kern-.1em\hbox{+\kern-.25em+}17} % C++17 symbolic name
+
+\newcommand{\TODO}{\textbf{TODO}}
+\newcommand{\eg}{\textit{e}.\textit{g}.}
+\newcommand{\ie}{\textit{i}.\textit{e}.}
+\newcommand{\etc}{\textit{etc}.}
+
+% CFA programming language, based on ANSI C (with some gcc additions)
+\lstdefinelanguage{CFA}[ANSI]{C}{
+	morekeywords={_Alignas,_Alignof,__alignof,__alignof__,asm,__asm,__asm__,_At,_Atomic,__attribute,__attribute__,auto,
+		_Bool,catch,catchResume,choose,_Complex,__complex,__complex__,__const,__const__,disable,dtype,enable,__extension__,
+		fallthrough,fallthru,finally,forall,ftype,_Generic,_Imaginary,inline,__label__,lvalue,_Noreturn,one_t,otype,restrict,_Static_assert,
+		_Thread_local,throw,throwResume,trait,try,typeof,__typeof,__typeof__,zero_t},
+}%
+
+\lstset{
+language=CFA,
+columns=fullflexible,
+basicstyle=\linespread{0.9}\sf,							% reduce line spacing and use sanserif font
+stringstyle=\tt,										% use typewriter font
+tabsize=4,												% 4 space tabbing
+xleftmargin=\parindent,									% indent code to paragraph indentation
+% extendedchars=true,									% allow ASCII characters in the range 128-255
+% escapechar=§,											% LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
+mathescape=true,										% LaTeX math escape in CFA code $...$
+keepspaces=true,										%
+showstringspaces=false,									% do not show spaces with cup
+showlines=true,											% show blank lines at end of code
+aboveskip=4pt,											% spacing above/below code block
+belowskip=3pt,
+% replace/adjust listing characters that look bad in sanserif
+literate={-}{\raisebox{-0.15ex}{\texttt{-}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
+	{~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {_}{\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}1 {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
+	{<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2,
+% moredelim=**[is][\color{red}]{®}{®},					% red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
+% moredelim=**[is][\color{blue}]{ß}{ß},					% blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
+% moredelim=**[is][\color{OliveGreen}]{¢}{¢}, 			% green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
+% moredelim=[is][\lstset{keywords={}}]{¶}{¶}, 			% keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^
+}% lstset
+
+% inline code @...@
+\lstMakeShortInline@
+
+% ACM Information
 \citestyle{acmauthoryear}
-
-\newcommand{\CFA}{C$\mathbf\forall$}
-\newcommand{\TODO}{\textbf{TODO}}
 
 \acmJournal{PACMPL}
@@ -49,5 +98,4 @@
 \ccsdesc[300]{Software and its engineering~Source code generation}
 
-% \abstract{Abstract goes here.}
 \begin{abstract}
 \TODO{} Write abstract.
@@ -59,7 +107,96 @@
 
 \section{Introduction \& Background}
-\CFA{}\footnote{Pronounced ``C-for-all'', and written \CFA{} or Cforall.} is an evolutionary modernization of the C programming language which aims to add modern language features to C while maintaining both source compatibility with C and a familiar mental model for programmers. This paper describes how generic types are designed and implemented in \CFA{}, and how they interact with \CFA{}'s polymorphic functions.
-
-\CFA{}'s polymorphism was originally formalized by \citet{Ditchfield92}, and first implemented by \citet{Bilson03}.
+
+\CFA{}\footnote{Pronounced ``C-for-all'', and written \CFA{} or Cforall.} is an evolutionary extension of the C programming language which aims to add modern language features to C while maintaining both source compatibility with C and a familiar mental model for programmers. This paper describes how generic types are designed and implemented in \CFA{}, and how they interact with \CFA{}'s polymorphic functions.
+
+\subsection{Polymorphic Functions}
+
+\CFA{}'s polymorphism was originally formalized by \citet{Ditchfield92}, and first implemented by \citet{Bilson03}. The signature feature of \CFA{} is parametric-polymorphic functions; such functions are written using a @forall@ clause (which gives the language its name): 
+\begin{lstlisting}
+forall(otype T)
+T identity(T x) {
+    return x;
+}
+
+int forty_two = identity(42); // T is bound to int, forty_two == 42
+\end{lstlisting}
+The @identity@ function above can be applied to any complete object type (or ``@otype@''). The type variable @T@ is transformed into a set of additional implicit parameters to @identity@, which encode sufficient information about @T@ to create and return a variable of that type. The \CFA{} implementation passes the size and alignment of the type represented by an @otype@ parameter, as well as an assignment operator, constructor, copy constructor and destructor. Here, the runtime cost of polymorphism is spread over each polymorphic call, due to passing more arguments to polymorphic functions; preliminary experiments have shown this overhead to be similar to \CC{} virtual function calls. 
+
+Since bare polymorphic types do not provide a great range of available operations, \CFA{} provides a \emph{type assertion} mechanism to provide further information about a type:
+\begin{lstlisting}
+forall(otype T | { T twice(T); })
+T four_times(T x) {
+    return twice( twice(x) );
+}
+
+double twice(double d) { return d * 2.0; } // (1)
+
+double magic = four_times(10.5); // T is bound to double, uses (1) to satisfy type assertion
+\end{lstlisting}
+These type assertions may be either variable or function declarations that depend on a polymorphic type variable. @four_times@ can only be called with an argument for which there exists a function named @twice@ that can take that argument and return another value of the same type; a pointer to the appropriate @twice@ function is passed as an additional implicit parameter to the call of @four_times@.
+
+Monomorphic specializations of polymorphic functions can themselves be used to satisfy type assertions. For instance, @twice@ could have been defined using the \CFA{} syntax for operator overloading as:
+\begin{lstlisting}
+forall(otype S | { S ?+?(S, S); })
+S twice(S x) { return x + x; }  // (2)
+\end{lstlisting} 
+This version of @twice@ works for any type @S@ that has an addition operator defined for it, and it could have been used to satisfy the type assertion on @four_times@. 
+The compiler accomplishes this by creating a wrapper function calling @twice // (2)@ with @S@ bound to @double@, then providing this wrapper function to @four_times@\footnote{\lstinline@twice // (2)@ could also have had a type parameter named \lstinline@T@; \CFA{} specifies renaming of the type parameters, which would avoid the name conflict with the type variable \lstinline@T@ of \lstinline@four_times@.}.
+
+\subsection{Traits}
+
+\CFA{} provides \emph{traits} as a means to name a group of type assertions, as in the example below:
+\begin{lstlisting}
+trait has_magnitude(otype T) {
+    bool ?<?(T, T);  // comparison operator for T
+    T -?(T);  // negation operator for T
+    void ?{}(T*, zero_t);  // constructor from 0 literal
+};
+
+forall(otype M | has_magnitude(M))
+M abs( M m ) {
+    M zero = { 0 };  // uses zero_t constructor from trait
+    return m < zero ? -m : m;
+}
+
+forall(otype M | has_magnitude(M))
+M max_magnitude( M a, M b ) {
+    return abs(a) < abs(b) ? b : a; 
+}
+\end{lstlisting}
+
+Semantically, traits are simply a named lists of type assertions, but they may be used for many of the same purposes that interfaces in Java or abstract base classes in \CC{} are used for. Unlike Java interfaces or \CC{} base classes, \CFA{} types do not explicitly state any inheritance relationship to traits they satisfy; this can be considered a form of structural inheritance, similar to implementation of an interface in Go, as opposed to the nominal inheritance model of Java and \CC{}. Nominal inheritance can be simulated with traits using marker variables or functions:
+\begin{lstlisting}
+trait nominal(otype T) {
+    T is_nominal;
+};
+
+int is_nominal;  // int now satisfies the nominal trait
+{
+    char is_nominal; // char satisfies the nominal trait
+}
+// char no longer satisfies the nominal trait here  
+\end{lstlisting}
+
+Traits, however, are significantly more powerful than nominal-inheritance interfaces; firstly, due to the scoping rules of the declarations that satisfy a trait's type assertions, a type may not satisfy a trait everywhere that the type is declared, as with @char@ and the @nominal@ trait above. Secondly, traits may be used to declare a relationship among multiple types, a property that may be difficult or impossible to represent in nominal-inheritance type systems:
+\begin{lstlisting}
+trait pointer_like(otype Ptr, otype El) {
+    lvalue El *?(Ptr); // Ptr can be dereferenced into a modifiable value of type El
+}
+
+struct list {
+    int value;
+    list *next;  // may omit "struct" on type names
+};
+
+typedef list *list_iterator;
+
+lvalue int *?( list_iterator it ) {
+    return it->value;
+}
+\end{lstlisting}
+
+In the example above, @(list_iterator, int)@ satisfies @pointer_like@ by the user-defined dereference function, and @(list_iterator, list)@ also satisfies @pointer_like@ by the built-in dereference operator for pointers. Given a declaration @list_iterator it@, @*it@ can be either an @int@ or a @list@, with the meaning disambiguated by context (\eg, @int x = *it;@ interprets @*it@ as an @int@, while @(*it).value = 42;@ interprets @*it@ as a @list@).
+While a nominal-inheritance system with associated types could model one of those two relationships by making @El@ an associated type of @Ptr@ in the @pointer_like@ implementation, few such systems could model both relationships simultaneously.
 
 \bibliographystyle{ACM-Reference-Format}
