24 Type system
t, t1, t2, ... are type expressions. v1, v2, ... are type variables
('a, 'b, 'foo, ...).
24.1 Basic types
int
, float
, string
, bool
, void
,
written as is.
24.2 Function type
Function type is written as follows:
*(t (t1, t2, ..., tn))
where n >= 0. One might note that this is somewhat different from ML where
all functions take just one parameter (which can be tuple or another
function, but this is not the point). This is closer to C's function
notation.
24.3 Tuples
*(t1, t2, ..., tn)
where n >= 2.
24.4 Structures
struct <v1, v2, ..., vn> NAME {
t1 f1;
t2 f2;
...
tm fm;
}
Structures that can be invalid (i.e. null):
opt_struct <v1, v2, ..., vn> NAME {
t1 f1;
t2 f2;
...
tm fm;
}
24.5 Unions (datatypes)
union <v1, v2, ..., vn> NAME {
t1 f1;
t2 f2;
...
tm fm;
}
where n >= 0, m >= 1. If n == 0, <> can be omitted. fi are field names.
24.6 Named types
Structures and unions can be later on referred with:
<t1, t2, ..., tn> NAME
where n >= 0. If n == 0, <> can be omitted.
24.7 Foreword
*
in front of tuple and function types is (crude) way to convince
Bison, that there are none reduce/reduce conflicts in grammar. I guess
there aren't even without `*', but tell it to yacc... (this problem is
referred to in Bison manual, there are some workarounds, however I was
unable to make use of it).