next up previous contents
Next: About this document ... Up: Gont for C programmers Previous: Constructing functional values   Contents

Typesystem

ti and t are type expressions. vi are type variables ('a, 'b, 'foo, ...).

Basic types: int, float, string, bool, void, written as is.

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.

Tuples:

        *[t1, t2, ..., tn]

where n >= 2.

Structures are defined with:

        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;
        }

Unions (datatypes) are defined with:

        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.

They can be later on referred with:

        <t1, t2, ..., tn> NAME

where n >= 0. If n == 0, <> can be omitted.

`*' 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).


next up previous contents
Next: About this document ... Up: Gont for C programmers Previous: Constructing functional values   Contents
Micha³ Moskal 2001-11-27