Changeset 21f4dff


Ignore:
Timestamp:
Jul 30, 2024, 11:44:16 PM (3 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
6740533e
Parents:
9476549
Message:

Add motivation for trait

Location:
doc/theses/jiada_liang_MMath
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/jiada_liang_MMath/background.tex

    r9476549 r21f4dff  
    371371Calling on type with no mathcing @foo()@ implemented, such as int, causes a compile time type assertion error.
    372372
     373\subsection{trait}
    373374A @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@ .
     375the asserting functions in to a named \newterm{trait}.
    375376
    376377\begin{cfa}
  • doc/theses/jiada_liang_MMath/trait.tex

    r9476549 r21f4dff  
    22\label{c:trait}
    33
     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
     7write function polymorphic over enumerated type in \CC:
     8\begin{cfa}
     9#include <type_traits>
     10
     11template<typename T>
     12@concept Enumerable = std::is_enum<T>::value;@
     13
     14template<@Enumerable@ T>
     15void f(T) {}
     16\end{cfa}
     17The @std::is_enum@ and other \CC @traits@ are a compile-time interfaces to query type information.
     18While named the same as @trait@, it is orthogonal to \CFA trait, as the latter being defined as
     19a 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}
     23forall(T | @CfaEnum(T)@)
     24void f(T) {}
     25\end{cfa}
     26
    427\section{CfaEnum and TypedEnum}
    5 
    628\CFA defines attribute functions @label()@ and @posn()@ for all \CFA enumerations,
    729and therefore \CFA enumerations fulfills the type assertions with the combination.
Note: See TracChangeset for help on using the changeset viewer.