Changeset 21f4dff for doc/theses/jiada_liang_MMath
- Timestamp:
- Jul 30, 2024, 11:44:16 PM (4 months ago)
- Branches:
- master
- Children:
- 6740533e
- Parents:
- 9476549
- Location:
- doc/theses/jiada_liang_MMath
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/background.tex
r9476549 r21f4dff 371 371 Calling on type with no mathcing @foo()@ implemented, such as int, causes a compile time type assertion error. 372 372 373 \subsection{trait} 373 374 A @forall@ clause can asserts on multiple types and with multiple asserting functions. A common practice in \CFA is to group 374 the asserting functions in to a named @trait@.375 the asserting functions in to a named \newterm{trait}. 375 376 376 377 \begin{cfa} -
doc/theses/jiada_liang_MMath/trait.tex
r9476549 r21f4dff 2 2 \label{c:trait} 3 3 4 % Despite parametric polymorphism being a pivotal feature of \CFA, for a long time, there was not 5 % a technique to write functions being polymorphic over enumerated types. 6 \CC introduced @std::is_enum@ trait on \CC{11} and @concepts@ on \CC{20}; with the combination, users can 7 write function polymorphic over enumerated type in \CC: 8 \begin{cfa} 9 #include <type_traits> 10 11 template<typename T> 12 @concept Enumerable = std::is_enum<T>::value;@ 13 14 template<@Enumerable@ T> 15 void f(T) {} 16 \end{cfa} 17 The @std::is_enum@ and other \CC @traits@ are a compile-time interfaces to query type information. 18 While named the same as @trait@, it is orthogonal to \CFA trait, as the latter being defined as 19 a collection of assertion to be satisfied by a polymorphic type. 20 21 \CFA provides @CfaEnum@ and @TypedEnum@ traits to supports polymorphic functions for \CFA enumeration: 22 \begin{cfa} 23 forall(T | @CfaEnum(T)@) 24 void f(T) {} 25 \end{cfa} 26 4 27 \section{CfaEnum and TypedEnum} 5 6 28 \CFA defines attribute functions @label()@ and @posn()@ for all \CFA enumerations, 7 29 and therefore \CFA enumerations fulfills the type assertions with the combination.
Note: See TracChangeset
for help on using the changeset viewer.