From a5ef1a855284f509c10dbc3ac493735dae8e11c0 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 14 Jul 2020 14:35:52 -0400 Subject: [PATCH] Type aliases: Restore personhood to people without a home (#438) --- content/types/type-aliases.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/content/types/type-aliases.md b/content/types/type-aliases.md index 07e1ea38..dd79ac45 100644 --- a/content/types/type-aliases.md +++ b/content/types/type-aliases.md @@ -67,10 +67,10 @@ interface HasName interface HasAge fun age(): U32 -interface HasAddress - fun address(): String +interface HasFeelings + fun feeling(): String -type Person is (HasName & HasAge & HasAddress) +type Person is (HasName & HasAge & HasFeelings) ``` This use of complex types applies to traits, not just interfaces: @@ -82,13 +82,13 @@ trait HasName trait HasAge fun age(): U32 => 42 -trait HasAddress - fun address(): String => "3 Abbey Road" +trait HasFeelings + fun feeling(): String => "Great!" -type Person is (HasName & HasAge & HasAddress) +type Person is (HasName & HasAge & HasFeelings) ``` -There's another new concept here: the type has a `&` in it. This is similar to the `|` of a __union__ type: it means this is an __intersection__ type. That is, it's something that must be _all_ of `HasName`, `HasAge` _and_ `HasAddress`. +There's another new concept here: the type has a `&` in it. This is similar to the `|` of a __union__ type: it means this is an __intersection__ type. That is, it's something that must be _all_ of `HasName`, `HasAge` _and_ `HasFeelings`. But the use of `type` here is exactly the same as the enumeration example above, it's just providing a name for a type that is otherwise a bit tedious to type out over and over.