Amalgam Types

Many types can be mixed together to create one, big type. A type that represents many other types mixed together is called amalgam type.

It is represented by putting side by side 2 or more types.

For instance, the following snippet:

[
    a: ''
]
[
    b: ''
]

can be approximately translated to:

[
    a: ''
    b: ''
]

when evaluated.

Important

The above “approximative translation” has a flaw: it mixes the local scopes of the types to be mixed together. According to the above “approximative translation”, a should know about the existence of b, and conversely. In reality, they should not – the scope of each type should be kept separated.

To rephrase: evaluating the following snippet should abruptly halt the execution of the interpreter:

[
    T =: ''
]
[
    b: T
]

with this informative message (see nominal reference accessors):

error: could not find T in context:
at <row>:<col>:
    b: T
       ^

To summarize, the above “approximative translation” serves only to visually show that amalam types effectively consists in many types mixet together as if they were a single type. It is not meant to represent the exact reality.

It may be worth noting that a type can be amalgamated with the string type.

For instance, the following snippet:

'' [a: '']

represents the [a: ''] structural type and the '' string type together, as if they were one single type.

Also, members that are common between types to be amalgamated together are also amalgamated together. For instance, in the following snippet:

[
    a: ''
]
[
    a: [nested: '']
]

the former type’s a member is amalgamated with the latter type’s a member. The whole expression is therefore equivalent to the [a: '' [nested: '']] structural type.

Note

The following kind of amalgamation has simply been deduced from the previous one.

When two types – one subtype of the other (and not the other way around) – are amalgamated together, then the more concrete type of the two wins over the other and becomes the resulting type of the expression. For instance, this snippet:

[
    a: [name: '']
    b: ''
]
[
    a: []
]

represents the former [a: [name: ''] b: ''] structural type.