Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala推理__Scala_Type Inference - Fatal编程技术网

Scala推理_

Scala推理_,scala,type-inference,Scala,Type Inference,我是scala(fxnl编程)的新手,不过我在下面的一些地方把它放在上下文中 list.map(_ * 1) 我不能完全理解这句话 val story = (catch _) andThen (eat _) 虽然我可以从电话中推断 story(new Cat, new Bird) 下划线用作参数位置的占位符,我想了解它背后的概念。语句 不正确-因为catch是关键字 但这是正确的: scala> def caught(x:Int) = x + 8 caught: (x: Int)

我是scala(fxnl编程)的新手,不过我在下面的一些地方把它放在上下文中

list.map(_ * 1) 
我不能完全理解这句话

val story = (catch _) andThen (eat _)
虽然我可以从电话中推断

story(new Cat, new Bird)
下划线用作参数位置的占位符,我想了解它背后的概念。

语句

不正确-因为catch是关键字

但这是正确的:

scala> def caught(x:Int) = x + 8
caught: (x: Int)Int

scala> def eat(x:Int) = x + 3
eat: (x: Int)Int

scala> val story = (caught _) andThen (eat _) // story is function.
story: Int => Int = <function1>

scala> story(90) // You put 90 - parameter for caught (first _). It returns 90 + 8 and put it to eat (second _). eat function return 98 + 3
res0: Int = 101
scala>def捕获(x:Int)=x+8
捕获:(x:Int)Int
scala>defeat(x:Int)=x+3
吃:(x:Int)Int
scala>val story=(捕获)和(吃)//story是函数。
故事:Int=>Int=
scala>story(90)//您将90-参数放在catch(first)上。它返回90+8并将其放入食物中(秒)。eat函数返回98+3
res0:Int=101
语句

不正确-因为catch是关键字

但这是正确的:

scala> def caught(x:Int) = x + 8
caught: (x: Int)Int

scala> def eat(x:Int) = x + 3
eat: (x: Int)Int

scala> val story = (caught _) andThen (eat _) // story is function.
story: Int => Int = <function1>

scala> story(90) // You put 90 - parameter for caught (first _). It returns 90 + 8 and put it to eat (second _). eat function return 98 + 3
res0: Int = 101
scala>def捕获(x:Int)=x+8
捕获:(x:Int)Int
scala>defeat(x:Int)=x+3
吃:(x:Int)Int
scala>val story=(捕获)和(吃)//story是函数。
故事:Int=>Int=
scala>story(90)//您将90-参数放在catch(first)上。它返回90+8并将其放入食物中(秒)。eat函数返回98+3
res0:Int=101

浏览此答案,了解下划线的用法:感谢您在搜索时发现此为,浏览此答案,了解下划线的用法:感谢您在搜索时发现此为