Binding Rules
Now that we have seen all available types, we will see the last section on the type system: the binding rules. These specify whether or not you can put a value of a given type inside a variable of another type. Most of these are pretty straightforward, but listing them makes things easier on complex cases.
A type A
is bindable to type B
if and only if one of the following cases apply:
B
is*
.A
andB
are the same.- Both
A
andB
are constant references and their inner types are bindable. - Both
A
andB
are mutable references and their inner types are bindable. A
is a structural type and its alias is bindable toB
.B
is a structural type andA
is bindable to its alias.A
is a template andB
follows its constraints and the substitution is not incoherent with the rest.B
is a template andA
follows its constraints and the substitution is not incoherent with the rest.A
is a sum type and all its variants are bindable toB
B
is a sum type andA
is bindable to any of its variants.- Both
A
andB
are product types with the same length and every typeA_i
is bindable toB_i
. - Both
A
andB
are the same parametric type with the same class and every type parameterA_i
is bindable to the type parameterB_i
. - Both
A
andB
are function types and both their argument types and return types are bindable.
As you can see, checking whether or not two types are bindable is a recursive process, but the ideas are very intuitive given the descriptions in their corresponding sections. Now that we have defined one of the key aspects of Ryna, we will begin explaining how to use the language.