I'm a little confused at what is going on here with this recursive type definition:
type Func func() (int, int, Func)
Note: I know how to use it via trial and error but I'm very uncertain as to what it(the recursive type definition) is.
package main
import "fmt"
func fib(x int) int {
if x == 0 {
return 0
} else if x == 1 {
return 1
} else {
return fib(x-1) + fib(x-2)
}
}
type Func func() (int, int, Func)
func get_fib(x int) (int, int, Func) {
return x, fib(x), func() (int, int, Func) { return get_fib(x + 1) }
}
func main() {
d, n, f := get_fib(10)
d1, n1, f1 := f()
d2, n2, _ := f1()
fmt.Println(d, n)
fmt.Println(d1, n1)
fmt.Println(d2, n2)
}
Can anyone shed some light on what's created in the above recursive type definition?