What really T is in this piece of code? recursive deceleration?
package main
import "fmt"
type T func() T
func main() {
var a T
a = func() T {
return a
}
fmt.Printf("%#v", a)
}
http://play.golang.org/p/zt4CBXgrmI
Edit: I have been using Go for more than a year.
It looks like a function type. In the declaration, T is a parameterless function that returns a T, so a function that returns a function. That is the type declaration. a is of this type T.
a is a function that returns itself, so these lines basically all do the same:
fmt.Printf("%#v", a)
fmt.Printf("%#v", a())
fmt.Printf("%#v", a()()()()())
I can't think of a good use for this, but then again, I'm far from experienced in Go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With