Cone Language Reference

alias

On this page

Note: an alias of a type is implemented. An alias of a function, a global, a module or a method is not yet.

alias#

To give some type a second name, declare an alias in the appropriate module's global scope (it may not be placed anywhere else):

alias Noderef = Rc[mut, Node];

In this example, wherever Noderef is used in this module, it will be understood to mean Rc[mut, Node].

What follows the = is the alias's target. It is resolved when the program is compiled, and is never a computation: an alias names something that already exists, it does not make a value.

An alias is a second spelling for one type, not a second type: it creates no distinct type and nothing is asserted by using one name rather than the other. To declare a type of your own that enriches an existing one with methods, which is a distinct type, see Enriching a concrete type.

Because it is a second spelling and not a second thing, it also qualifies what it names. Where alias Sample = Reading; names a struct, Sample.make(1) reaches the same static function Reading.make(1) does.

An alias may be declared pub, which makes the name visible outside its module; the type it names keeps its own visibility, so an alias never lends out something private. A chain of aliases is ordinary — one alias may name another — but a chain that comes back to itself names no type at all, and is refused where it is written.

typedef, the statement's former spelling, is retired. It remains a keyword, and the compiler reports a typedef statement where it is written.