Changes in / [3a7cd15:1f11818]
- Location:
- doc/theses/jiada_liang_MMath
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/background.tex
r3a7cd15 r1f11818 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}374 373 A @forall@ clause can asserts on multiple types and with multiple asserting functions. A common practice in \CFA is to group 375 the asserting functions in to a named \newterm{trait}.374 the asserting functions in to a named @trait@ . 376 375 377 376 \begin{cfa} -
doc/theses/jiada_liang_MMath/trait.tex
r3a7cd15 r1f11818 2 2 \label{c:trait} 3 3 4 % Despite parametric polymorphism being a pivotal feature of \CFA, for a long time, there was not5 % 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 can7 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 as19 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 27 4 \section{CfaEnum and TypedEnum} 5 28 6 \CFA defines attribute functions @label()@ and @posn()@ for all \CFA enumerations, 29 7 and therefore \CFA enumerations fulfills the type assertions with the combination. … … 97 75 \end{cfa} 98 76 99 \section{Discussion: Static Type Information} 100 @CfaEnum@ and @TypedEnum@ are approximations to \CFA Enumerations and Typed Enumerations: they are not 101 assertions on a type being an enumerated type, 102 but rather types being shared an interfaces with \CFA enumerations. 103 \CC's @type_traits@ is fundamentally different than \CFA's traits: \CC's @type_traits@ are descriptions 104 of compile time type information 105 \footnote{Concepts can check if a \CC class implement a certain method, 106 but it is to probe a static type information of a class having a such member.} 107 , while \CFA's trait describe how a type can be used, 108 which is a closer paradigm to a trait system in languages such as Scala and Rust. 109 However, Scala and Rust's traits are nominative: 110 a type explicitly declare a named traits to be of its type; while in \CFA, 111 type implements all functions declares in a trait to implicitly be of the trait type. 112 113 If to support static type information, \CFA needs new piece of syntax to distinguish static type 114 query from function calls, for example: 115 \begin{cfa} 116 forall(T | { T::is_enum; }); 117 \end{cfa} 118 When to call a polymorphic function @foo(T)@ with assertions set @S@ and function call argument @a@, \CFA 119 determines if there is an overloaded name @a@ that has non-zero conversion cost to all assertions in @S@. 120 As a consequence, @is_enum@ can be a \CFA directive that immediately trim down the search space of @a@ to 121 be some enumerated types. In fact, because \CFA stores symbols maps to enumeration in a standalone data structure. 122 Limiting search space to enumeration improve on \CFA resolution speed. 123 124 While assertion on static type information seems improvement on expressivity, it is a challenge to 125 extend its capability without a fully functional pre-processsor that evaluate constant expression as \CC 126 compilers does. The described @is_enum@ manipulate compiler behaviour, which cannot be easily extended to 127 other usage cases. Therefore, \CFA currently does not support @is_enum@ and utalizes traits as a workaround. 128 129 130 \section{Bounded and Serial} 77 \subsection{Bounded and Serial} 131 78 A bounded type defines a lower bound and a upper bound. 132 79 \begin{cfa}
Note: See TracChangeset
for help on using the changeset viewer.