32 lines
744 B
Pony
32 lines
744 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]
|
|
|
|
for colour in ColourList().values() do
|
|
|
|
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.
|