# Changeset ffc9f5a

Ignore:
Timestamp:
Apr 13, 2017, 8:17:28 AM (6 years ago)
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
5103d7a
Parents:
19518e8
Message:

fixed a few typos in generic types

File:
1 edited

### Legend:

Unmodified
 r19518e8 % int is_nominal;                                                               $\C{// int now satisfies the nominal trait}$ % \end{lstlisting} % % % Traits, however, are significantly more powerful than nominal-inheritance interfaces; most notably, traits may be used to declare a relationship \emph{among} multiple types, a property that may be difficult or impossible to represent in nominal-inheritance type systems: % \begin{lstlisting} % }; % typedef list *list_iterator; % % % lvalue int *?( list_iterator it ) { return it->value; } % \end{lstlisting} In many languages, functions can return at most one value; however, many operations have multiple outcomes, some exceptional. Consider C's @div@ and @remquo@ functions, which return the quotient and remainder for a division of integer and floating-point values, respectively. Consider C's @div@ and @remquo@ functions, which return the quotient and remainder for a division of integer and floating-point values, respectively. \begin{lstlisting} typedef struct { int quo, rem; } div_t; \end{lstlisting} Clearly, this approach is straightforward to understand and use; therefore, why do most programming language not support this obvious feature or provide it awkwardly? therefore, why do most programming languages not support this obvious feature or provide it awkwardly? The answer is that there are complex consequences that cascade through multiple aspects of the language, especially the type-system. This section show these consequences and how \CFA deals with them. The addition of multiple-return-value (MRV) functions are useless without a syntax for accepting multiple values at the call-site. The simplest mechanism for capturing the return values is variable assignment, allowing the valuse to be retrieved directly. The simplest mechanism for capturing the return values is variable assignment, allowing the values to be retrieved directly. As such, \CFA allows assigning multiple values from a function into multiple variables, using a square-bracketed list of lvalue expressions (as above), called a \emph{tuple}. However, functions also use \emph{composition} (nested calls), with the direct consequence that MRV functions must also support composition to be orthogonal with single-returning-value (SRV) functions, \eg: However, functions also use \emph{composition} (nested calls), with the direct consequence that MRV functions must also support composition to be orthogonal with single-return-value (SRV) functions, \eg: \begin{lstlisting} printf( "%d %d\n", div( 13, 5 ) );                      $\C{// return values seperated into arguments}$ printf( "%d %d\n", qr ); \end{lstlisting} \CFA also supports \emph{tuple indexing} to access single components of a typle expression: \CFA also supports \emph{tuple indexing} to access single components of a tuple expression: \begin{lstlisting} [int, int] * p = &qr;                                           $\C{// tuple pointer}$ In the call to @g@, the values @y@ and @10@ are structured into a single argument of type @[int, int]@ to match the parameter type of @g@. Finally, in the call to @h@, @x@ is flattened to yield an argument list of length 3, of which the first component of @x@ is passed as the first parameter of @h@, and the second component of @x@ and @y@ are structured into the second argument of type @[int, int]@. The flexible structure of tuples permits a simple and expressive function call syntax to work seamlessly with both SRF and MRF, and with any number of arguments of arbitrarily complex structure. The flexible structure of tuples permits a simple and expressive function call syntax to work seamlessly with both SRV and MRV functions, and with any number of arguments of arbitrarily complex structure. f([5, "hello"]); \end{lstlisting} where @[5, "hello"]@ is flattened, giving argument list @5, "hello"@, and @T@ binds to @int@ and @U@ binds to @const char*@. where @[5, "hello"]@ is flattened, giving argument list @5, "hello"@, and @T@ binds to @int@ and @U@ binds to @const char@. Tuples, however, may contain polymorphic components. For example, a plus operator can be written to add two triples together. T2 field_2; }; _tuple3_(int, double, int) y; _tuple3(int, double, int) y; } \end{lstlisting}