Why a function value assignment to f is not a composite literal?
Go lang specification Composite literals says below, hence function value cannot be constructed with composite Literal.
Composite literals construct values for structs, arrays, slices, and maps and create a new value each time they are evaluated
However, the function value assignment to f in the code looks as a composite literal expression for type func() int.
Is there a reason function object cannot be constructed as a composite literal?
package main
import (
"fmt"
)
func main(){
var x int = 0
var f func() int
f = func() int{ x++; return x * x } // <---- Why this cannot be a composite literal?
fmt.Println(f()) // 1
fmt.Println(f()) // 4
fmt.Println(f()) // 9
// Define a type for "func() int" type
type SQUARE func() int
g := SQUARE{ x++; return x * x} // <--- Error with Invalid composite literal type: SQUARE
fmt.Println(g())
}