at:tutorial:appendix
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
at:tutorial:appendix [2008/07/10 16:24] – * tvcutsem | at:tutorial:appendix [2008/07/10 16:32] – * tvcutsem | ||
---|---|---|---|
Line 505: | Line 505: | ||
==== Structural Types ==== | ==== Structural Types ==== | ||
+ | |||
+ | The module ''/ | ||
+ | |||
+ | A structural type can be branded with type tags. In this case, objects only conform to the type if they are structurally conformant **and** if they are tagged with the structural type's brands. | ||
+ | |||
+ | Use the '' | ||
+ | |||
+ | < | ||
+ | def PersonProtocol := protocol: { | ||
+ | def name; | ||
+ | def age; | ||
+ | } named: `Person; | ||
+ | </ | ||
+ | |||
+ | The '' | ||
+ | |||
+ | < | ||
+ | def tom := object: { | ||
+ | def name := " | ||
+ | def age() { 24 }; | ||
+ | } implements: PersonProtocol; | ||
+ | </ | ||
+ | |||
+ | You can also create a protocol from an object: | ||
+ | < | ||
+ | |||
+ | You can test protocol conformance in either of two styles: | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | You can also force a '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | More usage examples of structural types can be found in the unit test defined in the file '' | ||
==== Traits ==== | ==== Traits ==== |
at/tutorial/appendix.txt · Last modified: 2021/09/24 10:28 by elisag