22 Type system
t, t1, t2, ... are type expressions. v1, v2, ... are type variables
('a, 'b, 'foo, ...).
22.1 Basic types
int
, float
, string
, bool
, void
,
written as is.
22.2 Function type
Function type is written as follows:
*(t1, t2, ..., tn) -> t
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.
22.3 Tuples
*[t1, t2, ..., tn]
where n >= 2.
22.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;
}
22.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.
22.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.
22.7 Foreword
*
in front of tuple and function types is (crude) way to convince
ocamlyacc (Bison has the same problem, though), 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).