以下函数f
以名字方式调用参数:
scala> def f(xs: => List[Int]) = xs
f: (xs: => List[Int])List[Int]
然后,我尝试使用List of call by-name参数定义一个函数:
scala> def f(xs: List[=> Int]) = xs
<console>:1: error: identifier expected but '=>' found.
def f(xs: List[=> Int]) = xs
^
但那失败了。
我能做到:
scala> def f(xs: List[Function0[Int]]) = xs
f: (xs: List[() => Int])List[() => Int]
但是,是否可以使用List
语法在=>
的参数上使用call-by?