<- ^ ->
Unions

10   Unions

Union are more closely related to ML's datatypes then to C's unions. The basic difference is that Gont compiler remembers which member is currently stored in union.

Unions are defined as:

        union exp {
                int Const;
                void Var;
                *[exp, exp] Add;
                *[exp, exp] Sub;
                *[exp, exp] Mul;
                *[exp, exp] Div;
        }
This union can be later on used for processing symbolic expressions. For example:

        // f = (x / 10) + x
        exp f = Add[Div[Var, Const[10]], Var];
        exp g = Var;            // both forms
        exp h = Var[];          // are correct
You can access union components only using pattern matching (there is no `.' notation). Pattern matching is discussed in Section 14.

<- ^ ->
Unions