Ignore:
Timestamp:
Sep 14, 2024, 5:07:55 PM (5 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
8c79dc3c
Parents:
3733643
Message:

final proofread of thesis

File:
1 edited

Legend:

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

    r3733643 rdcfcf368  
    3939For example, the week, the weekdays, the weekend, and every second day of the week.
    4040\begin{cfa}[morekeywords={in}]
    41 for ( cursor in Mon, Tue, Wed, Thu, Fri, Sat, Sun } ... $\C[3.75in]{// week}$
    42 for ( cursor in Mon, Tue, Wed, Thu, Fri } ...   $\C{// weekday}$
    43 for ( cursor in Sat, Sun } ...                                  $\C{// weekend}$
    44 for ( cursor in Mon, Wed, Fri, Sun } ...                $\C{// every second day of week}\CRT$
     41for ( cursor in Mon, Tue, Wed, Thu, Fri, Sat, Sun ) ... $\C[3.75in]{// week}$
     42for ( cursor in Mon, Tue, Wed, Thu, Fri ) ...   $\C{// weekday}$
     43for ( cursor in Sat, Sun ) ...                                  $\C{// weekend}$
     44for ( cursor in Mon, Wed, Fri, Sun ) ...                $\C{// every second day of week}\CRT$
    4545\end{cfa}
    4646A set can have a partial or total ordering, making it possible to compare set elements, \eg Monday is before Tuesday and Tuesday is after.
     
    7373
    7474The term \newterm{enumeration} defines a type with a set of new constants, and the term \newterm{enumerator} represents an arbitrary alias name \see{\VRef{s:CEnumeration} for the name derivations}.
    75 An enumerated type can have three fundamental properties, \newterm{label} (name), \newterm{order} (position), and \newterm{value} (payload).
     75An enumerated type can have the following properties: \newterm{label} (name), \newterm{order} (position), and \newterm{value} (payload).
    7676\begin{cquote}
    7777\sf\setlength{\tabcolsep}{3pt}
     
    234234% The association between ADT and enumeration occurs if all the constructors have a unit (empty) type, \eg @struct unit {}@.
    235235% Note, the unit type is not the same as \lstinline{void}.
    236 In terms of functional programming linguistics, enumerations often refers to a @unit type@ ADT, where @unit type@ is a type
    237 that carry no information. The unit type is different than @void@ in C, because @void@ is type has no value, i.e., it is a empty set.
    238 In constract, unit type has exactly one value, often called a @nil@ value.
    239 Because of this distinction, it is not possbile to have a variable to have type @void@ or to be assigned with a value @void@.
    240 In practice, @void@ in C is more like an annotation that nothing is expected in this place. A function takes @void@ as parameter
    241 is essentially a function that expects no parameter. A function that return @void@ cannot be used as a parameter of a function that expects no
    242 parameter. Therefore, the following code is illegal in C:
     236In terms of functional programming linguistics, enumerations often refer to a @unit type@ ADT, which is a set with the @nil@ value carrying no information.
     237The unit type is different from type @void@ in C, because @void@ has no value, which is an empty set.
     238Hence, @void@ is a C annotation that nothing is expected in this place.
     239For example, a function that takes a @void@ parameter and returns a @void@ is a function that expects no parameters and returns nothing.
     240\begin{cfa}
     241void foo( void );
     242foo(); $\C{// no arguments and no result}$
     243\end{cfa}
     244Because of this distinction, it is impossible to have a variable of type @void@, to assign a @void@ value, or have a function taking and returning multiple @void@s.
     245\begin{cfa}
     246void v;                 $\C{// disallowed}$
     247v = void;
     248[ void, void ] bar( void, void );
     249\end{cfa}
     250Programming languages often use an empty parameter list to imply no value and no return type for empty return.
     251\begin{cfa}
     252[] bar(); $\C{// \CFA empty/empty prototype}$
     253\end{cfa}
     254However, C is saddled with an empty parameter list meaning a list of unknown type parameters, \ie @var_arg@, which is changed to @void@ in \CC/\CFA.
     255As a result, a function that returns @void@ cannot be used as a parameter of a function that expects no parameter.
    243256\begin{cfa}
    244257void foo( void );
     
    246259\end{cfa}
    247260
    248 This is a more notably issue when to use @variant@ to simulate @ADT@: @void@ cannot be used as an empty variant. To solve this problem,
    249 \CC introduced @monstate@, a type that can be instantiated as a value, but holds no information. There is no standard representation of
    250 @unit@ in C, and it is often approximated by a user-defined type that has no field, for example:
    251 \begin{cfa}
    252 struct Empty {} e;              $\C{// empty type}$
    253 Empty bar( Empty );
    254 bar(@bar(e)@);
    255 \end{cfa}
    256 @Empty@ is a close approximation to @unit@ if and only if @Empty@ is the only representation of @unit@ in the program. If a program has
    257 a second type, say @Nothing@, that also tries to resemble @unit@, then @unit@ concepts falls apart.
     261This issue arose when simulating an ADT using a \CC @variant@: @void@ cannot be used as an empty variant.
     262To solve this problem, \CC introduced @std::monstate@~\cite{C++monstate}, a type that can be instantiated as a value but holds no information.
     263A similar approximation in C is to define a @struct@ type with no fields.
     264\begin{cfa}
     265struct Unit {} e;               $\C{// empty type}$
     266Unit bar( Unit );
     267bar( @bar( e )@ );
     268\end{cfa}
     269Because @std::monostate@ and @Unit@ are user-defined types versus part of the type system, they are only an approximation to @unit@ because other @unit@ types can be defined.
    258270
    259271In the Haskell ADT:
Note: See TracChangeset for help on using the changeset viewer.