- File:
-
- 1 edited
-
doc/proposals/concurrency/text/cforall.tex (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/concurrency/text/cforall.tex
r6090518 r5c4f2c2 52 52 % ====================================================================== 53 53 \section{Operators} 54 Overloading also extends to operators. The syntax for denoting operator-overloading is to name a routine with the symbol of the operator and question marks where the arguments of the operation occur, e.g.:54 Overloading also extends to operators. The syntax for denoting operator-overloading is to name a routine with the symbol of the operator and question marks where the arguments of the operation appear, e.g.: 55 55 \begin{cfacode} 56 56 int ++? (int op); //unary prefix increment … … 107 107 % ====================================================================== 108 108 \section{Parametric Polymorphism} 109 Routines in \CFA can also be reused for multiple types. This capability is done using the \code{forall} clause , which gives \CFA its name. \code{forall} clausesallow separately compiled routines to support generic usage over multiple types. For example, the following sum function works for any type that supports construction from 0 and addition :109 Routines in \CFA can also be reused for multiple types. This capability is done using the \code{forall} clauses, which allow separately compiled routines to support generic usage over multiple types. For example, the following sum function works for any type that supports construction from 0 and addition : 110 110 \begin{cfacode} 111 111 //constraint type, 0 and + … … 124 124 Since writing constraints on types can become cumbersome for more constrained functions, \CFA also has the concept of traits. Traits are named collection of constraints that can be used both instead and in addition to regular constraints: 125 125 \begin{cfacode} 126 trait sum able( otype T ) {126 trait summable( otype T ) { 127 127 void ?{}(T *, zero_t); //constructor from 0 literal 128 128 T ?+?(T, T); //assortment of additions … … 131 131 T ?++(T *); 132 132 }; 133 forall( otype T | sum able(T) ) //use trait133 forall( otype T | summable(T) ) //use trait 134 134 T sum(T a[], size_t size); 135 135 \end{cfacode} … … 139 139 % ====================================================================== 140 140 \section{with Clause/Statement} 141 Since \CFA lacks the concept of a receiver, certain functions end -up needing to repeat variable names often. To remove this inconvenience, \CFA provides the \code{with} statement, which opens an aggregate scope making its fields directly accessible (like Pascal).141 Since \CFA lacks the concept of a receiver, certain functions end up needing to repeat variable names often. To remove this inconvenience, \CFA provides the \code{with} statement, which opens an aggregate scope making its fields directly accessible (like Pascal). 142 142 \begin{cfacode} 143 143 struct S { int i, j; };
Note:
See TracChangeset
for help on using the changeset viewer.