ava/type-aliases.md

23 lines
670 B
Markdown

# Type Aliases
An `alias` is an alternative name for some type. It is useful as either a local
rename or as a way to constrain types without overhead. An alias _cannot_ have a
type constructor.
The power of an alias comes from the fact that within the scope of the alias
definition, the alias and its bound type are treated as identical_.
```
alias Username := String
fn username: (candidate: String) => Either[InvalidUsername, Username]
-- do validation... and maybe it passes...
right(candidate)
end fn
instance Show[Username]
fn show: (value: Username) => String
value
end fn
end instance
end alias
```