pony/type_aliases/main.pony

35 lines
908 B
Pony

primitive Red
primitive Blue
primitive Green
// Let Colour be an alias for the union type (Red | Blue | Green)
type Colour is (Red | Blue | Green)
// ColourList is a constant representing the union type
primitive ColourList
fun apply(): Array[Colour] =>
[Red; Green; Blue]
actor Main
new create(env: Env) =>
for colour in ColourList().values() do
env.out.print("I should be printing a colour
but I don't know how to cast to string")
end
// Type aliases can also be used to give simpler names to complex types
interface HasName
fun name(): String
interface HasAge
fun age(): U32
interface HasFeelings
fun feeling(): String
// Let Person be an alias for the intersection of those three types
// This makes it easier to refer to
type Person is (HasName & HasAge & HasFeelings)
// You can do this with traits as well as interfaces.