ava/notes/type-aliases.md

670 B

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