Changes in / [1f11818:3a7cd15]


Ignore:
Location:
doc/theses/jiada_liang_MMath
Files:
2 edited

Legend:

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

    r1f11818 r3a7cd15  
    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

    r1f11818 r3a7cd15  
    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.
     
    7597\end{cfa}
    7698
    77 \subsection{Bounded and Serial}
     99\section{Discussion: Static Type Information}
     100@CfaEnum@ and @TypedEnum@ are approximations to \CFA Enumerations and Typed Enumerations: they are not
     101assertions on a type being an enumerated type,
     102but 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
     104of compile time type information
     105\footnote{Concepts can check if a \CC class implement a certain method,
     106but 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,
     108which is a closer paradigm to a trait system in languages such as Scala and Rust.
     109However, Scala and Rust's traits are nominative:
     110a type explicitly declare a named traits to be of its type; while in \CFA,
     111type implements all functions declares in a trait to implicitly be of the trait type.
     112
     113If to support static type information, \CFA needs new piece of syntax to distinguish static type
     114query from function calls, for example:
     115\begin{cfa}
     116forall(T | { T::is_enum; });
     117\end{cfa}
     118When to call a polymorphic function @foo(T)@ with assertions set @S@ and function call argument @a@, \CFA
     119determines if there is an overloaded name @a@ that has non-zero conversion cost to all assertions in @S@.
     120As a consequence, @is_enum@ can be a \CFA directive that immediately trim down the search space of @a@ to
     121be some enumerated types. In fact, because \CFA stores symbols maps to enumeration in a standalone data structure.
     122Limiting search space to enumeration improve on \CFA resolution speed.
     123
     124While assertion on static type information seems improvement on expressivity, it is a challenge to
     125extend its capability without a fully functional pre-processsor that evaluate constant expression as \CC
     126compilers does. The described @is_enum@ manipulate compiler behaviour, which cannot be easily extended to
     127other usage cases. Therefore, \CFA currently does not support @is_enum@ and utalizes traits as a workaround.
     128
     129
     130\section{Bounded and Serial}
    78131A bounded type defines a lower bound and a upper bound.
    79132\begin{cfa}
Note: See TracChangeset for help on using the changeset viewer.