Index: doc/theses/jiada_liang_MMath/main.tex
===================================================================
--- doc/theses/jiada_liang_MMath/main.tex	(revision 85034edc709b6220ea9dabc9a07efab793e34dab)
+++ doc/theses/jiada_liang_MMath/main.tex	(revision bab2917ddf427236b02c457fe13904bbca581868)
@@ -73,37 +73,4 @@
 
 
-
-%%
-%% Submission ID.
-%% Use this when submitting an article to a sponsored event. You'll
-%% receive a unique submission ID from the organizers
-%% of the event, and this ID should be used as the parameter to this command.
-%%\acmSubmissionID{123-A56-BU3}
-
-%%
-%% For managing citations, it is recommended to use bibliography
-%% files in BibTeX format.
-%%
-%% You can then either use BibTeX with the ACM-Reference-Format style,
-%% or BibLaTeX with the acmnumeric or acmauthoryear sytles, that include
-%% support for advanced citation of software artefact from the
-%% biblatex-software package, also separately available on CTAN.
-%%
-%% Look at the sample-*-biblatex.tex files for templates showcasing
-%% the biblatex styles.
-%%
-
-%%
-%% The majority of ACM publications use numbered citations and
-%% references.  The command \citestyle{authoryear} switches to the
-%% "author year" style.
-%%
-%% If you are preparing content for an event
-%% sponsored by ACM SIGGRAPH, you must use the "author year" style of
-%% citations and references.
-%% Uncommenting
-%% the next command will enable that style.
-%%\citestyle{acmauthoryear}
-
 %%
 %% end of the preamble, start of the body of the document source.
@@ -128,5 +95,5 @@
 %% article.
 \begin{abstract}
-    An enumeration, or enum in short, is a type that defines a list of named constant values in C. Cforall extends the enumeration with additional features.
+    An enumeration, or enum in short, is a type that defines a list of named constant values in C. C uses integral type as the underlying representation of enum. Cforall extends C enum to allow more types, including custom types, to be used as enumeration inner representation.
 \end{abstract}
 
@@ -143,10 +110,63 @@
 
 \section{C-Style Enum}
+\begin{lstlisting}[style=CStyle, label{lst:weekday}]
+enum Weekday { Monday, Tuesday, Wednesday, Thursday=10, Friday, Saturday, Sunday };
+\end{lstlisting}
+Cforall supports the C-Style enumeration (C-enum for short). It has the same syntax as C and resembles the same language semantics. In code~\ref{lst:weekday} example, the syntax defines an enum class $Weekday$ with enumerators $Monday$, $Tuesday$, $Wednesday$, $Thursday$, $Friday$, $Saturday$ and $Sunday$ in order. The successor of $Tuesday$ is $Monday$ and the predecessor of $Tuesday$ is $Wednesday$. Enumerators have an integral type, either being explicitly initialized by an initializer or being assigned a value by the compiler. For example, $Thursday$ has been assigned with value $10$. If not explicitly initialized, the first value of an enum, $Monday$ in the $Weekday$ example, has the integer value 0. Other uninitialized enum value has a value that is equal to their successor $+ 1$. The enum value $Tuesday$, $Wednesday$, $Friday$, $Saturday$, and $Sunday$ have value 1, 2, 11, 12, and 13 respectively. 
+
+\begin{lstlisting}[label{lst:enum_scope}, style=CStyle]
+{
+    {
+        enum RGB {R, G, B};
+        int i = R  // i == 0
+    }
+    int j = G; // ERROR! G is not declared in this scope
+}
+\end{lstlisting}
+C-enums are unscoped: enumerators declared inside of an enum are visible in the enclosing scope of the enum class.
+
+\section{Cforall-Style Enum}
+\begin{lstlisting}[style=CStyle, label{lst:color}]
+enum Color(char *) { Red="R", Green="G", Blue="B"  };
+\end{lstlisting}
+A Cforall enumeration is parameterized by a type declared. Cforall allows any oType in the enum declaration, and values assigned to enumerators must be in the declared type.
+
+\section{Enumerable Type Traits}
+A trait is a collection of constraints in Cforall, which can be used to describe types. Cforall standard library defines traits to categorize types that are related enumeration features.
+\subsection{Enumerable}
+A type is enumerable if it can map an integer to a value. 
 \begin{lstlisting}[style=CStyle]
-enum Weekday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
-\end{lstlisting}
-Cforall supports the classic C-Style enumeration (C-enum for short) and its syntax is consistent with C. No internal data structure is generated for C-enum, and C-enum does not provide the Cforall-enum interface methods.
-
-\section{Cforall Enum}
+forall(T)
+trait Enumerable {
+    T value( *class_name* , int );
+};
+\end{lstlisting}
+The parameter class name stands for the name of an enumeration class, Weekday, for example.
+
+\subsection{AutoInitializable}
+\begin{lstlisting}[style=CStyle]
+forall(T)
+trait AutoInitializable {
+  void ?()( T & t, zero_t );
+  void ?()( T & t, one_t );
+  S& ?+=?( T & t, one_t );
+  void ?{}( T &, T ); 
+  T ?{}( T &, T ); 
+};
+\end{lstlisting}
+
+\subsection{AutoInitializable}
+\begin{lstlisting}[style=CStyle]
+forall(T)
+trait AutoInitializable {
+  void ?()( T & t, zero_t );
+  void ?()( T & t, one_t );
+  S& ?+=?( T & t, one_t );
+  void ?{}( T &, T ); 
+  T ?{}( T &, T ); 
+};
+\end{lstlisting}
+A type is AutoInitializable if it has defined a zero\_t constructor, a one\_t constructor, an addition assignment operator, a copy constructor, and a copy assignment operator.
+
 \subsection{Enumerable Type}
 \begin{lstlisting}[style=CStyle]
@@ -160,5 +180,8 @@
 };
 \end{lstlisting}
-A type is enumerable in Cforall if it has defined 0, 1, increment operator, copy constructor, and copy assignment operator.
+
+
+
+
 
 (Should change the definition of enumerable to something else. Maybe auto-constructible. If a type is not auto-constructible, all enumeration must be explicitly initialized)
@@ -224,9 +247,15 @@
 Names of labels are distinct in an enum declaration. Cforall therefore allows indexing an enum value with its string representation of a label.
 
-\subsection{Range Functions and Iteration (Placeholder)}
+\subsection{Iteration and Range}
+A Cforall enum is iterable and supports range function.
 \begin{lstlisting}[caption={Range Functions}, label{lst:range_functions}, style=CStyle]
-enum Weekday( 
-    Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
-};
+struct string;
+enum(string) Weekday( 
+    Monday = "M", Tuesday = "Tu", ...
+};
+for ( i; Weekday ) { sout | i; }
+>> M Tu W Th F Sat Sun
+for ( Monday ~= Tuesday )
+>> M Tu
 \end{lstlisting}
 
@@ -249,4 +278,5 @@
 }
 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+enum Color.Label;
 Companion( string ) Color = { 
     .values = [ "Red", "Green", "Blue" ],
@@ -255,9 +285,22 @@
 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 forall( T | enumerable(T) )
-T* value( Companion, int );
-char* label( Companion, int );
-\end{lstlisting}
-
-\subsection{TODO - Type trait for Cforall - Enum}
+T value( Companion companion, int index ) { return companion.values[ index ]; } 
+T value( Companion, enum Color.Label );
+char* label( Companion companion, int index ) { return companion.values[ index ]; }
+char* label( Companion, enum Color.Label );
+
+\end{lstlisting}
+
+
+\subsection{Companion Trait}
+Users can define the companion object themselves. A companion object should define an array of any type called values and an array of strings representing a label. Defining a companion object effectively creates a new enumerable type. 
+
+\subsection{Companion Mapping}
+
+
+
+\begin{lstlisting}[caption={Enum Type Functions}, label{lst:cforall_enum_functions}, style=CStyle]
+
+\end{lstlisting}
 %%
 %% If your work has an appendix, this is the place to put it.
