Skip to content

Instantly share code, notes, and snippets.

@hnsl
Created August 4, 2015 03:05
Show Gist options
  • Save hnsl/03e5953ec151558583cc to your computer and use it in GitHub Desktop.
Save hnsl/03e5953ec151558583cc to your computer and use it in GitHub Desktop.
golang interface experiments
type count int32
type incrementable interface {
Inc()
}
type countable interface {
incrementable
Dec()
}
func f(x countable) {
x.Inc()
x.Dec()
x.Dec()
}
/*func (x count) Inc() {
x = x + 1
}*/
func (x *count) Inc() {
*x = *x + 1
}
func (x *count) Dec() {
*x = *x - 1
}
func main() {
var x count = 4
f(&x)
os.Exit(int(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment