You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dyon supports types that are ad-hoc, or partially defined. An ad-hoc type can have any name not used by other Dyon types. It is common to use CamelCase.
An ad-hoc type has an optional inner type where you put more details about the type. When not specified, this is set to {}. For example Person and Person {} is the same type.
An ad-hoc type is not declared, but written directly in the function declaration.
Example:
fnnew_person(name:str) -> Person{return{ name: name }}
The inner type goes with the ad-hoc type and vice versa. An error is shown if you try to use a different ad-hoc type or a different inner type where an ad-hoc type is expected.
Addition and multiplication
Two ad-hoc types can be added if the inner type allows addition.
Dyon complains if you try to add an ad-hoc type with an inner type.
For example:
// Convert number to `km`fnkm(v:f64) -> km f64{return v }km(3) + km(4)// OK
km(3) + 4// ERROR
Before #638, multiplication is not allowed, because this often changes physical units.
After #638, multiplication is allowed, because one can override the multiplication operator to deal with physical units.
The text was updated successfully, but these errors were encountered:
Dyon supports types that are ad-hoc, or partially defined. An ad-hoc type can have any name not used by other Dyon types. It is common to use CamelCase.
An ad-hoc type has an optional inner type where you put more details about the type. When not specified, this is set to
{}
. For examplePerson
andPerson {}
is the same type.An ad-hoc type is not declared, but written directly in the function declaration.
Example:
The inner type goes with the ad-hoc type and vice versa. An error is shown if you try to use a different ad-hoc type or a different inner type where an ad-hoc type is expected.
Addition and multiplication
Two ad-hoc types can be added if the inner type allows addition.
Dyon complains if you try to add an ad-hoc type with an inner type.
For example:
Before #638, multiplication is not allowed, because this often changes physical units.
After #638, multiplication is allowed, because one can override the multiplication operator to deal with physical units.
The text was updated successfully, but these errors were encountered: