Changeset c13b2b8

Apr 17, 2017, 8:56:25 PM (4 years ago)
Peter A. Buhr <pabuhr@…>
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

condensed to 22 pages

1 edited


  • 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
    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}$
    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}$
    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.
    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.