pony/type_expressions/main.pony

32 lines
910 B
Pony

actor Main
new create(env: Env) =>
env.out.print("hlo wld")
// A tuple type is a sequence of types
var x: (String, U64)
x = ("hi", 3)
x = ("bye", 7)
// Pony supports tuple unpacking but calls it "destructuring"
// This assigns "bye" to y and 7 to z
(var y, var z) = x
// You can access the elements of tuples directly using this
// one weird syntax
y = x._1
z = x._2
// You can't assign elements of tuples. To change the value
// of a tuple you must reassign the whole thing.
x = ("wibble wobble", x._2)
// A union is a set of possible types
// This means "a is a String or None":
var a: (String | None)
a = "yeah yeah whatever static analysis tool"
// An intersection is a value that is more than one type at once
// An example from the standard library:
// type Map[K: (Hashable box & Comparable[K] box), V] is HashMap[K, V, HashEq[K]]
// K is Hashable *and* Comparable[K] at the same time