source: doc/theses/fangren_yu_MMath/background.tex @ 262a864

Last change on this file since 262a864 was 63b32f9d, checked in by Peter A. Buhr <pabuhr@…>, 6 days ago

temporarily add citations to background chapter

  • Property mode set to 100644
File size: 7.7 KB
Line 
1\chapter{Background}
2
3\cite{Melo17} \cite{Odersky01} \cite{Pierce00}
4
5\section{Polymorphism}
6
7ML~\cite{ML} was the first language to support parametric polymorphism.
8Like \CFA, it supports universal type parameters, but not the use of assertions and traits to constrain type arguments.
9Haskell~\cite{Haskell10} combines ML-style polymorphism, polymorphic data types, and type inference with the notion of type classes, collections of overloadable methods that correspond in intent to traits in \CFA.
10Unlike \CFA, Haskell requires an explicit association between types and their classes that specifies the implementation of operations.
11These associations determine the functions that are assertion arguments for particular combinations of class and type, in contrast to \CFA where the assertion arguments are selected at function call sites based upon the set of operations in scope at that point.
12Haskell also severely restricts the use of overloading: an overloaded name can only be associated with a single class, and methods with overloaded names can only be defined as part of instance declarations.
13
14\CC provides three disjoint polymorphic extensions to C: overloading, inheritance, and templates.
15The overloading is restricted because resolution does not use the return type, inheritance requires learning object-oriented programming and coping with a restricted nominal-inheritance hierarchy, templates cannot be separately compiled resulting in compilation/code bloat and poor error messages, and determining how these mechanisms interact and which to use is confusing.
16In contrast, \CFA has a single facility for polymorphic code supporting type-safe separate compilation of polymorphic functions and generic (opaque) types, which uniformly leverage the C procedural paradigm.
17The key mechanism to support separate compilation is \CFA's \emph{explicit} use of assumed type properties.
18Until \CC concepts~\cite{C++Concepts} are standardized (anticipated for \CCtwenty), \CC provides no way of specifying the requirements of a generic function beyond compilation errors during template expansion;
19furthermore, \CC concepts are restricted to template polymorphism.
20
21Cyclone~\cite{Grossman06} also provides capabilities for polymorphic functions and existential types, similar to \CFA's @forall@ functions and generic types.
22Cyclone existential types can include function pointers in a construct similar to a virtual function table, but these pointers must be explicitly initialized at some point in the code, which is a tedious and potentially error-prone process.
23Furthermore, Cyclone's polymorphic functions and types are restricted to abstraction over types with the same layout and calling convention as @void *@, \ie only pointer types and @int@.
24In \CFA terms, all Cyclone polymorphism must be dtype-static.
25While the Cyclone design provides the efficiency benefits discussed in Section~\ref{sec:generic-apps} for dtype-static polymorphism, it is more restrictive than \CFA's general model.
26Smith and Volpano~\cite{Smith98} present Polymorphic C, an ML dialect with polymorphic functions, C-like syntax, and pointer types;
27it lacks many of C's features, most notably structure types, and hence, is not a practical C replacement.
28
29Objective-C~\cite{obj-c-book} is an industrially successful extension to C.
30However, Objective-C is a radical departure from C, using an object-oriented model with message passing.
31Objective-C did not support type-checked generics until recently \cite{xcode7}, historically using less-efficient runtime checking of object types.
32The GObject~\cite{GObject} framework also adds object-oriented programming with runtime type-checking and reference-counting garbage collection to C;
33these features are more intrusive additions than those provided by \CFA, in addition to the runtime overhead of reference counting.
34Vala~\cite{Vala} compiles to GObject-based C, adding the burden of learning a separate language syntax to the aforementioned demerits of GObject as a modernization path for existing C code bases.
35Java~\cite{Java8} included generic types in Java~5, which are type checked at compilation and type erased at runtime, similar to \CFA's.
36However, in Java, each object carries its own table of method pointers, whereas \CFA passes the method pointers separately to maintain a C-compatible layout.
37Java is also a garbage-collected, object-oriented language, with the associated resource usage and C-interoperability burdens.
38
39D~\cite{D}, Go, and Rust~\cite{Rust} are modern compiled languages with abstraction features similar to \CFA traits, \emph{interfaces} in D and Go, and \emph{traits} in Rust.
40However, each language represents a significant departure from C in terms of language model, and none has the same level of compatibility with C as \CFA.
41D and Go are garbage-collected languages, imposing the associated runtime overhead.
42The necessity of accounting for data transfer between managed runtimes and the unmanaged C runtime complicates foreign-function interfaces to C.
43Furthermore, while generic types and functions are available in Go, they are limited to a small fixed set provided by the compiler, with no language facility to define more.
44D restricts garbage collection to its own heap by default, whereas Rust is not garbage collected and, thus, has a lighter-weight runtime more interoperable with C.
45Rust also possesses much more powerful abstraction capabilities for writing generic code than Go.
46On the other hand, Rust's borrow checker provides strong safety guarantees but is complex and difficult to learn and imposes a distinctly idiomatic programming style.
47\CFA, with its more modest safety features, allows direct ports of C code while maintaining the idiomatic style of the original source.
48
49
50\section{Tuples/variadics}
51
52\vspace*{-5pt}
53Many programming languages have some form of tuple construct and/or variadic functions, \eg SETL, C, KW-C, \CC, D, Go, Java, ML, and Scala.
54SETL~\cite{SETL} is a high-level mathematical programming language, with tuples being one of the primary data types.
55Tuples in SETL allow subscripting, dynamic expansion, and multiple assignment.
56C provides variadic functions through @va_list@ objects, but the programmer is responsible for managing the number of arguments and their types;
57thus, the mechanism is type unsafe.
58KW-C~\cite{Buhr94a}, a predecessor of \CFA, introduced tuples to C as an extension of the C syntax, taking much of its inspiration from SETL.
59The main contributions of that work were adding MRVF, tuple mass and multiple assignment, and record-member access.
60\CCeleven introduced @std::tuple@ as a library variadic-template structure.
61Tuples are a generalization of @std::pair@, in that they allow for arbitrary length, fixed-size aggregation of heterogeneous values.
62Operations include @std::get<N>@ to extract values, @std::tie@ to create a tuple of references used for assignment, and lexicographic comparisons.
63\CCseventeen proposes \emph{structured bindings}~\cite{Sutter15} to eliminate predeclaring variables and the use of @std::tie@ for binding the results.
64This extension requires the use of @auto@ to infer the types of the new variables; hence, complicated expressions with a nonobvious type must be documented with some other mechanism.
65Furthermore, structured bindings are not a full replacement for @std::tie@, as it always declares new variables.
66Like \CC, D provides tuples through a library variadic-template structure.
67Go does not have tuples but supports MRVF.
68Java's variadic functions appear similar to C's but are type safe using homogeneous arrays, which are less useful than \CFA's heterogeneously typed variadic functions.
69Tuples are a fundamental abstraction in most functional programming languages, such as Standard ML~\cite{sml}, Haskell, and Scala~\cite{Scala}, which decompose tuples using pattern matching.
Note: See TracBrowser for help on using the repository browser.