// Counter Spirit - Stateful example
// Mutation effects inferred automatically
gen Counter {
has value: Int
fun get() -> Int {
return this.value
}
fun increment() {
this.value = this.value + 1
println("Counter: " + this.value.to_string())
}
fun add(n: Int) -> Int {
this.value = this.value + n
return this.value
}
}
fun main() {
let c = Counter { value: 0 }
c.increment()
c.increment()
print("Final: " + c.get().to_string())
}