Changeset 20e409e for doc/refrat/refrat.tex
- Timestamp:
- Sep 24, 2015, 9:59:20 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 02e5ab6
- Parents:
- bfee448
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/refrat/refrat.tex
rbfee448 r20e409e 254 254 \subsubsection{Semantics} 255 255 256 CFA provides a capability for generic types; using this capability a single "generic type generator" 257 can be written that can represent multiple concrete type instantiations by substitution of the "type 258 parameters" of the generic type for concrete types. Syntactically a generic type generator is 259 represented by putting a forall specifier on a struct or union declaration, as defined in section 260 6.7.2.5. An instantiation of the generic type is written by specifying the type parameters in 261 parentheses after the name of the generic type generator, as in the following example:262 \begin{lstlisting} 263 forall( type T ) struct pair {256 \CFA provides a capability for generic types; using this capability a single "generic type 257 generator" can be written that can represent multiple concrete type instantiations by substitution 258 of the "type parameters" of the generic type for concrete types. Syntactically a generic type 259 generator is represented by putting a forall specifier on a struct or union declaration, as defined 260 in \VRef{forall}. An instantiation of the generic type is written by specifying the type parameters 261 in parentheses after the name of the generic type generator: 262 \begin{lstlisting} 263 forall( type T | sumable( T ) ) struct pair { 264 264 T x; 265 265 T y; 266 266 }; 267 268 267 pair( int ) p = { 3, 14 }; 269 268 \end{lstlisting} 270 269 271 270 The type parameters in an instantiation of a generic type must satisfy any constraints in the forall 272 specifier on the type generator declaration . The instantiation then has the semantics that would273 result if the type parameters were substituted into the type generator declaration by macro 274 substitution.271 specifier on the type generator declaration, e.g., \lstinline$sumable$. The instantiation then has 272 the semantics that would result if the type parameters were substituted into the type generator 273 declaration by macro substitution. 275 274 276 275 Polymorphic functions may have generic types as parameters, and those generic types may use type 277 parameters of the polymorphic function as type parameters of the generic type, as in the following 278 example: 276 parameters of the polymorphic function as type parameters of the generic type: 279 277 \begin{lstlisting} 280 278 forall( type T ) void swap( pair(T) *p ) {
Note: See TracChangeset
for help on using the changeset viewer.