File: types.tex

package info (click to toggle)
kaya 0.2.0-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,012 kB
  • ctags: 1,307
  • sloc: cpp: 6,691; haskell: 4,833; sh: 2,868; yacc: 768; makefile: 700; perl: 87
file content (91 lines) | stat: -rw-r--r-- 3,300 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
\section{Types}

\Kaya{} is a polymorphic statically typed language; i.e., types are
checked at compile time and values retain the same type throughout
their lifetime. While programmers of dynamically typed languages such
as Perl, Python or Lisp may consider this a drawback, there are two
major advantages. Firstly, several classes of programming error are
caught before the program is run, rather than at some possibly obscure
and difficult to reproduce point during execution. Secondly, static
typing allows the programmer to describe data structures more
precisely, which is a valuable aid both for the programmer and the
compiler.  Unlike more traditional statically typed languages such as
C++ and Java, however, it is not usually necessary to declare the
types of local variables, since these can (in almost all cases) be
inferred from context.

There are a number of primitive types, which can be combined into
various forms of compund types. Compound types can be built as
arrays (discussed in section \ref{arrays}), user defined types (in section
\ref{usertypes}), or function types (discussed
in section \ref{funtypes}). 

Programming is about manipulating data, and if data structures are
well designed, manipulating them should be easy. This was a point made
by Fred Brooks many years ago \cite{manmonth} and repeated by Eric
Raymond \cite{esr}. Therefore, \Kaya{} provides a notation for
accurately describing and manipulating data structures as algebraic
data types (a feature more commonly seen in functional languages such
as Haskell \cite{haskell-report} and ML \cite{ml}). Before looking at
program structure, and how to manipulate data, let us consider the
datatypes available in \Kaya{}.

\subsection{Primitive Types}

The primitive types in \Kaya{} are described in table \ref{primtable}.

\begin{table}[h]
\begin{tabular}{|l|l|l|}
\hline
Type name & Meaning & Example values\\
\hline
\CD{Int} & 32 bit Integers & \CD{42}, \CD{6}, \ldots \\
\CD{Char} & Characters & \CD{'a'}, \CD{'Z'},
\CD{'\SL{}n'}, 
\ldots \\
\CD{Bool} & Boolean & \CD{true}, \CD{false} \\
\CD{Float} & Floating point values & \CD{42.0}, \CD{3.1415},
\CD{2.718}, \ldots \\
\CD{String} & Strings of characters &
\CD{"Fish"},\CD{"Hello world\SL{}n"}, \ldots \\
\CD{File} & File handles & N/A \\
\CD{Exception} & Exceptions  &
\CD{Exception("Out Of Cheese Error",1)} \\
\CD{Ptr} & Foreign language pointers &
N/A \\
\CD{Void} & Empty type & none \\
\hline
\end{tabular}
\caption{Primitive Types}
\label{primtable}
\end{table}


There are no pointer types, other than pointers to foreign objects. In
\Kaya{} everything is a reference (and therefore, internally, a
pointer). The programmer, therefore, never needs to worry about any
memory management details; it is all handled by the run-time system
and the garbage collector (using the Boehm garbage collector
\cite{boehm-gc}).

C and Java programmers should note that all concrete types begin with
a capital letter. This is to allow a distinction with polymorphic type
variables (see section \ref{polymorphic}).

\subsection{Arrays}

\label{arrays}

\TODO{See the website for now}

\subsection{Polymorphic Types}
\label{polymorphic}

\subsection{User Defined Types}
\label{usertypes}

\TODO{See the website for now}

\subsection{Exceptions}
\label{exceptions}