This works
def func(f: => Int) = f
This dosn’t (inside class for example)
type EmptyFunct = => Int
or
type EmptyFunct = (=> Int)
Scala version 2.9
Two questions:
- Why dosn’t syntax sugar work in second case?
- How to define this function without syntax sugar?
=> Int is not exactly a function without parameter, it is an Int argument with call by name passing convention. (Of course, that is rather fine a point, as it is implemented by passing a function without parameter ).
The function without argument is written
() => Int. You can dotype EmptyFunct = () => Int.It is not a type. Inside func, f will be typed as an Int. An argument of type () => Int will not.
But