Changeset c13b2b8 for doc/generic_types
- Timestamp:
- Apr 17, 2017, 8:56:25 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, 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:
- 2ca35b1
- Parents:
- b31fbf2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/generic_types.tex
rb31fbf2 rc13b2b8 213 213 Since 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. 214 214 For example, the function @twice@ can be defined using the \CFA syntax for operator overloading: 215 \newpage216 215 \begin{lstlisting} 217 216 forall( otype T `| { T ?+?(T, T); }` ) T twice( T x ) { return x + x; } $\C{// ? denotes operands}$ … … 232 231 int comp( const void * t1, const void * t2 ) { return *(double *)t1 < *(double *)t2 ? -1 : 233 232 *(double *)t2 < *(double *)t1 ? 1 : 0; } 234 double vals[10] = { /* 10 floating-point values */ }; 235 double key = 5.0; 233 double key = 5.0, vals[10] = { /* 10 floating-point values */ }; 236 234 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); $\C{// search sorted array}$ 237 235 \end{lstlisting} … … 279 277 %\begin{tabular}{@{}l@{\hspace{1.5\parindent}}||@{\hspace{1.5\parindent}}l@{}} 280 278 \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; 279 short int MAX = ...; int MAX = ...; double MAX = ...; 280 short int s = MAX; int i = MAX; double d = MAX; $\C{// select correct MAX}$ 287 281 \end{lstlisting} 288 282 %\end{lstlisting} … … 828 822 This example showcases a variadic-template-like decomposition of the provided argument list. 829 823 The individual @print@ functions allow printing a single element of a type. 830 The polymorphic @print@ allows printing any list of types, as longas 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 thatcannot be done with @printf@ in C.824 The polymorphic @print@ allows printing any list of types, where as each individual type has a @print@ function. 825 The individual print functions can be used to build up more complicated @print@ functions, such as @S@, which cannot be done with @printf@ in C. 832 826 833 827 Finally, it is possible to use @ttype@ polymorphism to provide arbitrary argument forwarding functions. … … 1107 1101 In addition, there are interesting future directions for the polymorphism design. 1108 1102 Notably, \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 virtualdispatch.1103 \CFA polymorphic functions uses a dynamic virtual-dispatch. 1110 1104 The 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. 1111 1105 Two 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.