Changeset 1dc6df0 for doc/generic_types
- Timestamp:
 - Apr 16, 2017, 9:45:31 AM (9 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:
 - 0aad606
 - Parents:
 - 4635c79
 - File:
 - 
      
- 1 edited
 
- 
          
  doc/generic_types/generic_types.tex (modified) (4 diffs)
 
 
Legend:
- Unmodified
 - Added
 - Removed
 
- 
      
doc/generic_types/generic_types.tex
r4635c79 r1dc6df0 257 257 For example, it is possible to write a type-safe \CFA wrapper @malloc@ based on the C @malloc@: 258 258 \begin{lstlisting} 259 forall( dtype T | sized(T) ) T * malloc( void ) { return (T *) (void *)malloc( (size_t)sizeof(T) ); }259 forall( dtype T | sized(T) ) T * malloc( void ) { return (T *)malloc( sizeof(T) ); } 260 260 int * ip = malloc(); $\C{// select type and size from left-hand side}$ 261 261 double * dp = malloc(); … … 505 505 Consider C's @div@ and @remquo@ functions, which return the quotient and remainder for a division of integer and floating-point values, respectively. 506 506 \begin{lstlisting} 507 typedef struct { int quo, rem; } div_t; 507 typedef struct { int quo, rem; } div_t; $\C{// from include stdlib.h}$ 508 508 div_t div( int num, int den ); 509 509 double remquo( double num, double den, int * quo ); … … 759 759 \begin{lstlisting} 760 760 int f( [int, double], double ); 761 forall(otype T, otype U | { T f( T, U, U ); }) 762 void g( T, U ); 761 forall(otype T, otype U | { T f( T, U, U ); }) void g( T, U ); 763 762 g( 5, 10.21 ); 764 763 \end{lstlisting} … … 767 766 Whenever a candidate's parameter structure does not exactly match the formal parameter's structure, a thunk is generated to specialize calls to the actual function: 768 767 \begin{lstlisting} 769 int _thunk( int _p0, double _p1, double _p2 ) { 770 return f( [_p0, _p1], _p2 ); 771 } 768 int _thunk( int _p0, double _p1, double _p2 ) { return f( [_p0, _p1], _p2 ); } 772 769 \end{lstlisting} 773 770 so the thunk provides flattening and structuring conversions to inferred functions, improving the compatibility of tuples and polymorphism.  
  Note:
 See   TracChangeset
 for help on using the changeset viewer.