Changeset f3be342


Ignore:
Timestamp:
Apr 12, 2017, 9:50:45 AM (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-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
eaa2f3a1
Parents:
3720bf8f
Message:

more cleanup for pages 1-8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/generic_types.tex

    r3720bf8f rf3be342  
    327327% \end{lstlisting}
    328328
    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.
     329In 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.
    330330Hence, trait names play no part in type equivalence;
    331331the 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.
     332Nevertheless, trait names form a logical subtype-hierarchy with @dtype@ at the top, where traits often contain overlapping assertions, \eg operator @+@.
    333333Traits are used like interfaces in Java or abstract base-classes in \CC, but without the nominal inheritance-relationships.
    334334Instead, 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.
     
    471471\begin{lstlisting}
    472472forall(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;
    478479Since @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.
    479480
Note: See TracChangeset for help on using the changeset viewer.