Changeset c13b2b8


Ignore:
Timestamp:
Apr 17, 2017, 8:56:25 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
2ca35b1
Parents:
b31fbf2
Message:

condensed to 22 pages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/generic_types.tex

    rb31fbf2 rc13b2b8  
    213213Since bare polymorphic-types provide a restricted set of available operations, \CFA provides a \emph{type assertion}~\cite[pp.~37-44]{Alphard} mechanism to provide further type information, where type assertions may be variable or function declarations that depend on a polymorphic type-variable.
    214214For example, the function @twice@ can be defined using the \CFA syntax for operator overloading:
    215 \newpage
    216215\begin{lstlisting}
    217216forall( otype T `| { T ?+?(T, T); }` ) T twice( T x ) { return x + x; } $\C{// ? denotes operands}$
     
    232231int comp( const void * t1, const void * t2 ) { return *(double *)t1 < *(double *)t2 ? -1 :
    233232                                *(double *)t2 < *(double *)t1 ? 1 : 0; }
    234 double vals[10] = { /* 10 floating-point values */ };
    235 double key = 5.0;
     233double key = 5.0, vals[10] = { /* 10 floating-point values */ };
    236234double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp );      $\C{// search sorted array}$
    237235\end{lstlisting}
     
    279277%\begin{tabular}{@{}l@{\hspace{1.5\parindent}}||@{\hspace{1.5\parindent}}l@{}}
    280278\begin{lstlisting}
    281 short int MAX = ...;
    282 int MAX = ...;
    283 double MAX = ...;
    284 short int s = MAX;  $\C{// select correct MAX}$
    285 int i = MAX;
    286 double d = MAX;
     279short int MAX = ...;   int MAX = ...;  double MAX = ...;
     280short int s = MAX;    int i = MAX;    double d = MAX;   $\C{// select correct MAX}$
    287281\end{lstlisting}
    288282%\end{lstlisting}
     
    828822This example showcases a variadic-template-like decomposition of the provided argument list.
    829823The individual @print@ functions allow printing a single element of a type.
    830 The polymorphic @print@ allows printing any list of types, as long as each individual type has a @print@ function.
    831 The individual print functions can be used to build up more complicated @print@ functions, such as for @S@, which is something that cannot be done with @printf@ in C.
     824The polymorphic @print@ allows printing any list of types, where as each individual type has a @print@ function.
     825The individual print functions can be used to build up more complicated @print@ functions, such as @S@, which cannot be done with @printf@ in C.
    832826
    833827Finally, it is possible to use @ttype@ polymorphism to provide arbitrary argument forwarding functions.
     
    11071101In addition, there are interesting future directions for the polymorphism design.
    11081102Notably, \CC template functions trade compile time and code bloat for optimal runtime of individual instantiations of polymorphic functions.
    1109 \CFA polymorphic functions, by contrast, uses a dynamic virtual dispatch.
     1103\CFA polymorphic functions uses a dynamic virtual-dispatch.
    11101104The runtime overhead of this approach is low, but not as low as inlining, and it may be beneficial to provide a mechanism for performance-sensitive code.
    11111105Two promising approaches are an @inline@ annotation at polymorphic function call sites to create a template-specialization of the function (provided the code is visible) or placing an @inline@ annotation on polymorphic function-definitions to instantiate a specialized version for some set of types.
Note: See TracChangeset for help on using the changeset viewer.