\contentsline {lstlisting}{\numberline {3.1}A superclass and subclass in Java}{10}{lstlisting.3.1} \contentsline {lstlisting}{\numberline {3.2}A superclass and subclass in Haskell, modelled with phantom types}{11}{lstlisting.3.2} \contentsline {lstlisting}{\numberline {3.3}Java class hierarchy with multiple inheritance}{12}{lstlisting.3.3} \contentsline {lstlisting}{\numberline {3.4}Phantom types augmented by type classes can model multiple inheritance}{12}{lstlisting.3.4} \contentsline {lstlisting}{\numberline {3.5}Using only type classes to model multiple inheritance}{13}{lstlisting.3.5} \contentsline {lstlisting}{\numberline {3.6}Implementing and using \textsf {printf} in Template Haskell}{16}{lstlisting.3.6} \contentsline {lstlisting}{\numberline {3.7}Up/downcasting functionality for the \textsf {Super} object-oriented class}{20}{lstlisting.3.7} \contentsline {lstlisting}{\numberline {3.8}Using \textsf {fromSuperInstance} and \textsf {toSuperInstance} to perform casting}{20}{lstlisting.3.8} \contentsline {lstlisting}{\numberline {3.9}The \textsf {downcast} and \textsf {upcast} functions}{21}{lstlisting.3.9} \contentsline {lstlisting}{\numberline {3.10}Modelling a class hierarchy which includes class objects}{24}{lstlisting.3.10} \contentsline {lstlisting}{\numberline {3.11}The \textsf {getClassObject} function}{25}{lstlisting.3.11} \contentsline {lstlisting}{\numberline {4.1}Definitions of the \textsf {Message}, \textsf {Receiver}, and \textsf {MessageExpression} data types}{30}{lstlisting.4.1} \contentsline {lstlisting}{\numberline {4.2}Primitive \textsf {MessageExpression} functions}{31}{lstlisting.4.2} \contentsline {lstlisting}{\numberline {4.3}\textsf {sendMessageExpressionWithNoReply} interface}{32}{lstlisting.4.3} \contentsline {lstlisting}{\numberline {4.4}Other \textsf {sendMessageExpressionWith\emph {x}reply} functions}{33}{lstlisting.4.4} \contentsline {lstlisting}{\numberline {4.5}An ideal interface for \textsf {sendMessage}}{34}{lstlisting.4.5} \contentsline {lstlisting}{\numberline {4.6}Using ad-hoc polymorphism to write \textsf {setArgument}}{34}{lstlisting.4.6} \contentsline {lstlisting}{\numberline {4.7}Using existential types for an argument list}{35}{lstlisting.4.7} \contentsline {lstlisting}{\numberline {4.8}Using \lstinline {sendMessage} with a list of existential types}{36}{lstlisting.4.-30} \contentsline {lstlisting}{\numberline {4.9}Using Template Haskell versions of \textsf {printf} and \textsf {sendMessage}}{36}{lstlisting.4.9} \contentsline {lstlisting}{\numberline {4.10}\textsf {sendMessage} type signature with an arbitrary parameter}{37}{lstlisting.4.10} \contentsline {lstlisting}{\numberline {4.11}The \textsf {Arguments} type class}{38}{lstlisting.4.11} \contentsline {lstlisting}{\numberline {4.12}The \textsf {Arguments} type class, redux}{39}{lstlisting.4.12} \contentsline {lstlisting}{\numberline {4.13}The \textsf {sendMessageExpression} implementation using a \textsf {MessageReply} type class}{40}{lstlisting.4.13} \contentsline {lstlisting}{\numberline {4.14}The \textsf {sendMessage} implementation}{41}{lstlisting.4.14} \contentsline {lstlisting}{\numberline {4.15}Using \textsf {sendMessage}}{41}{lstlisting.4.15} \contentsline {lstlisting}{\numberline {4.16}Hashtable object manipulation in Java}{42}{lstlisting.4.16} \contentsline {lstlisting}{\numberline {4.17}Hashtable object manipulation in Haskell using \textsf {sendMessage}}{43}{lstlisting.4.17} \contentsline {lstlisting}{\numberline {4.18}Convenient hashtable component communication in Haskell}{43}{lstlisting.4.18} \contentsline {lstlisting}{\numberline {4.19}Implementing the \textsf {put} and \textsf {get} functions}{44}{lstlisting.4.19} \contentsline {lstlisting}{\numberline {4.20}The \textsf {ObjectArgument} type class}{45}{lstlisting.4.20} \contentsline {lstlisting}{\numberline {4.21}\textsf {overloadedMethod} in Java}{45}{lstlisting.4.21} \contentsline {lstlisting}{\numberline {4.22}Implementing \textsf {overloadedMethod} in Haskell}{46}{lstlisting.4.22} \contentsline {lstlisting}{\numberline {4.23}\textsf {put} and \textsf {get}, allowed only to operate on \textsf {Hashtable} and \textsf {FiniteMap} receiving objects}{47}{lstlisting.4.23} \contentsline {lstlisting}{\numberline {4.24}\textsf {put} and \textsf {get} implemented with the \textsf {DirectMessage} type class}{48}{lstlisting.4.24} \contentsline {lstlisting}{\numberline {4.25}Transparent \textsf {String} $\leftrightarrow $ \textsf {StringObject} marshalling}{49}{lstlisting.4.25} \contentsline {lstlisting}{\numberline {4.26}Implementation of the \textsf {$\#$} function}{50}{lstlisting.4.26} \contentsline {lstlisting}{\numberline {4.27}Using \textsf {$\#$} and \textsf {$>>=$} for succinct code}{51}{lstlisting.4.27} \contentsline {lstlisting}{\numberline {4.28}A Haskell component which uses an \emph {instance variables object}}{53}{lstlisting.4.28} \contentsline {lstlisting}{\numberline {5.1}An implementation of \textsf {sendMessage} which marshals exceptions}{55}{lstlisting.5.1}