Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type aliases: Restore personhood to people without a home #438

Merged
merged 1 commit into from
Jul 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions content/types/type-aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand Down