Changeset f3be342 for doc/generic_types
- Timestamp:
- Apr 12, 2017, 9:50:45 AM (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:
- eaa2f3a1
- Parents:
- 3720bf8f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/generic_types.tex
r3720bf8f rf3be342 327 327 % \end{lstlisting} 328 328 329 In summation, the \CFA type-system uses \emph{nominal typing} for concrete types, matching with the C type-system and \emph{structural typing} for polymorphic types.329 In summation, the \CFA type-system uses \emph{nominal typing} for concrete types, matching with the C type-system, and \emph{structural typing} for polymorphic types. 330 330 Hence, trait names play no part in type equivalence; 331 331 the names are simply macros for a list of polymorphic assertions, which are expanded at usage sites. 332 Nevertheless, trait names form a logical subtype-hierarchy with @dtype@ at the top, where traits often contain overlapping assertions .332 Nevertheless, trait names form a logical subtype-hierarchy with @dtype@ at the top, where traits often contain overlapping assertions, \eg operator @+@. 333 333 Traits are used like interfaces in Java or abstract base-classes in \CC, but without the nominal inheritance-relationships. 334 334 Instead, each polymorphic function (or generic type) defines the structural type needed for its execution (polymorphic type-key), and this key is fulfilled at each call site from the lexical environment, which is similar to Go~\citep{Go} interfaces. … … 471 471 \begin{lstlisting} 472 472 forall(dtype T) int lexcmp( pair( T *, T * ) * a, pair( T *, T * ) * b, int (* cmp)( T *, T * ) ) { 473 int c = cmp( a->first, b->first ); 474 if ( c == 0 ) c = cmp( a->second, b->second ); 475 return c; 476 } 477 \end{lstlisting} 473 return cmp( a->first, b->first ) ? : cmp( a->second, b->second ); 474 } 475 \end{lstlisting} 476 % int c = cmp( a->first, b->first ); 477 % if ( c == 0 ) c = cmp( a->second, b->second ); 478 % return c; 478 479 Since @pair(T *, T * )@ is a concrete type, there are no implicit parameters passed to @lexcmp@, so the generated code is identical to a function written in standard C using @void *@, yet the \CFA version is type-checked to ensure the fields of both pairs and the arguments to the comparison function match in type. 479 480
Note: See TracChangeset
for help on using the changeset viewer.