When it fires. A function type, such as func(int) string, is written
where a value is expected: as the initializer of a val, an argument, an
operand. A function type is a type, not a value. It can be written as an
expression only as an explicit type argument, as in
EmptyArray[func() int]().
Minimal repro.
package main
func main() {
val f = func(int) string
Println(f)
}
Error output.
error[GALA-E0103]: function type func(int) string is not a value
--> main.gala:4:13
|
4 | val f = func(int) string
| ^^^^^^^^^^^^^^^^ write a function type only where a type is expected, such as…
|
= hint: write a function type only where a type is expected, such as an explicit type argument (`EmptyArray[func() int]()`); a function value is a lambda, `(x int) => x + 1`
Fix. For a function value, write a lambda. Give the variable the function type if it should have one:
package main
func main() {
val f func(int) string = (n) => s"#$n"
Println(f(3))
}
Rationale. GALA writes a function value as a lambda, (x int) => x + 1,
and a function type only where a type goes. The grammar reads the list of an
explicit type argument as expressions, so a function type is accepted in
expression position there and rejected everywhere else.