Nam G VU
Nam G VU

Reputation: 35374

Function-type Variable declaration - typo on official golang document page

At golang.org blog here we have the syntax to declare a function-type variable

f func(func(int,int) int, int) func(int, int) int

and I don't understand since it should be as below i.e. without the last 'int'

f func(func(int,int) int, int) func(int, int)

I'm a Go newbie and I may misunderstand something here. So is that a typo?

Upvotes: 0

Views: 70

Answers (2)

Md. Al-Amin
Md. Al-Amin

Reputation: 1441

No, it's not a typo.

f func(func(int,int) int, int) func(int, int) int

It means the function returns a function that has 2 int params and an int return type.

Upvotes: 2

icza
icza

Reputation: 417582

Both are correct.

This:

f func(func(int,int) int, int) func(int, int) int

is a function f which takes 2 params, first is of type func(int,int) int, second is an int, and returns a function that has 2 int params and an int return type.

This:

f func(func(int,int) int, int) func(int, int)

is mostly the same, but the return function type only has 2 int params, and does not return anything.

So there is no typo in the doc.

Upvotes: 3

Related Questions