type expressions
This commit is contained in:
parent
b57a2e7afc
commit
018e91979a
|
@ -0,0 +1,30 @@
|
|||
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"
|
||||
(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
|
Loading…
Reference in New Issue