Changeset 7f2e87a for doc/theses


Ignore:
Timestamp:
Aug 25, 2024, 11:56:45 AM (35 hours ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
075c6d5
Parents:
7a37fcb1
Message:

first proofread of chapter 1

File:
1 edited

Legend:

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

    r7a37fcb1 r7f2e87a  
    11\chapter{Introduction}
    22
    3 Testing glossy abbreviations \gls{foo} and \gls{bar}, and glossy definitions \gls{git} and \gls{gulp}.
     3This thesis is exploratory work I did to understand, fix, and extend the \CFA type-system, specifically, the type resolver used to select polymorphic types among overloaded names.
     4The \CFA type-system has a number of unique features making it different from all other programming languages.
    45
    5 And use the glossy abbreviations \gls{foo} and \gls{bar}, and definitions \gls{git} and \gls{gulp} again.
     6Overloading allows programmers to use the most meaningful names without fear of name clashes within a program or from external sources, like include files.
     7\begin{quote}
     8There are only two hard things in Computer Science: cache invalidation and naming things. --- Phil Karlton
     9\end{quote}
     10Experience from \CC and \CFA developers is that the type system implicitly and correctly disambiguates the majority of overloaded names, \ie it is rare to get an incorrect selection or ambiguity, even among hundreds of overloaded (variables and) functions.
     11In many cases, a programmer has no idea there are name clashes, as they are silently resolved, simplifying the development process.
     12Depending on the language, ambiguous cases are resolved using some form of qualification and/or casting.
     13
     14One of the key goals in \CFA is to push the boundary on overloading, and hence, overload resolution.
     15
     16
     17\subsection{Operator Overloading}
     18
     19Virtually all programming languages overload the arithmetic operators across the basic types using the number and type of parameters and returns.
     20Like \CC, \CFA also allows these operators to be overloaded with user-defined types.
     21The syntax for operator names uses the @'?'@ character to denote a parameter, \eg prefix and infix increment operators: @?++@, @++?@, and @?+?@.
     22\begin{cfa}
     23struct S { int i, j };
     24S @?+?@( S op1, S op2 ) { return (S){ op1.i + op2.i, op1.j + op2.j }; }
     25S s1, s2;
     26s1 = s1 @+@ s2;                 $\C[1.75in]{// infix call}$
     27s1 = @?+?@( s1, s2 );   $\C{// direct call}\CRT$
     28\end{cfa}
     29The type system examines each call size and selects the best matching overloaded function based on the number and types of the arguments.
     30If there are mixed-mode operands, @2 + 3.5@, the type system, like in C/\CC, attempts (safe) conversions, converting the argument type(s) to the parameter type(s).
     31
     32
     33\subsection{Function Overloading}
     34
     35Both \CFA and \CC allow function names to be overloaded, as long as their prototypes differ in the number and type of parameters and returns.
     36\begin{cfa}
     37void f( void );                 $\C[1.75in]{// (1): no parameter}$
     38void f( char );                 $\C{// (2): overloaded on the number and parameter type}$
     39void f( int, int );             $\C{// (3): overloaded on the number and parameter type}$
     40f( 'A' );                               $\C{// select (2)}\CRT$
     41\end{cfa}
     42In this case, the name @f@ is overloaded depending on the number and parameter types.
     43The type system examines each call size and selects the best match based on the number and types of the arguments.
     44Here, there is a perfect match for the call, @f( 'A' )@ with the number and parameter type of function (2).
     45
     46Ada, Scala, and \CFA type-systems also use the return type in resolving a call, to pinpoint the best overloaded name.
     47\begin{cfa}
     48int f( void );                  $\C[1.75in]{// (4); overloaded on return type}$
     49double f( void );               $\C{// (5); overloaded on return type}$
     50int i = f();                    $\C{// select (4)}$
     51double d = f();                 $\C{// select (5)}\CRT$
     52\end{cfa}
     53
     54
     55\subsection{Variable Overloading}
     56Unlike almost all programming languages, \CFA has variable overloading within a scope, along with shadow overloading in nested scopes.
     57\begin{cfa}
     58void foo( double d );
     59int v;                              $\C[1.75in]{// (1)}$
     60double v;                               $\C{// (2) variable overloading}$
     61foo( v );                               $\C{// select (2)}$
     62{
     63        int v;                          $\C{// (3) shadow overloading}$
     64        double v;                       $\C{// (4) and variable overloading}$
     65        foo( v );                       $\C{// select (4)}\CRT$
     66}
     67\end{cfa}
     68The \CFA type system simply treats overloaded variables as an overloaded function returning a value with no parameters.
     69Hence, no significant effort is required to support this feature.
Note: See TracChangeset for help on using the changeset viewer.