这两个scala函数定义之间的区别

时间:2015-09-29 03:35:51

标签: scala

我正在阅读斯卡拉学校的基础教程 https://twitter.github.io/scala_school/basics.html。

我试图了解这两个定义之间的区别是什么。

另外,如果有人可以在这种情况下解释currying和部分应用。

def multiply(m: Int,n: Int): Int = m * n

C:\Users\Samuel>pip install noise Collecting noise Using cached noise-1.2.2.tar.gz Installing collected packages: noise Running setup.py install for noise Complete output from command "c:\program files\python 3.5\python.exe" -c "import setuptools, tokenize;__file__='C:\\Users\\Samuel\\AppData\\Local\\Temp\\pip-build-e9dlwpm2\\noise\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Samuel\AppData\Local\Temp\pip-7tgvnyfe-record\install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build\lib.win-amd64-3.5 creating build\lib.win-amd64-3.5\noise copying perlin.py -> build\lib.win-amd64-3.5\noise copying setup.py -> build\lib.win-amd64-3.5\noise copying shader.py -> build\lib.win-amd64-3.5\noise copying shader_noise.py -> build\lib.win-amd64-3.5\noise copying test.py -> build\lib.win-amd64-3.5\noise copying __init__.py -> build\lib.win-amd64-3.5\noise running build_ext building 'noise._simplex' extension error: Unable to find vcvarsall.bat ---------------------------------------- Command ""c:\program files\python 3.5\python.exe" -c "import setuptools, tokenize;__file__='C:\\Users\\Samuel\\AppData\\Local\\Temp\\pip-build-e9dlwpm2\\noise\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Samuel\AppData\Local\Temp\pip-7tgvnyfe-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Samuel\AppData\Local\Temp\pip-build-e9dlwpm2\noise

1 个答案:

答案 0 :(得分:1)

区别仅在于您实际调用此方法的方式。在 second 情况下,您唯一的选择是同时传递两个参数,例如first。在Int => Int情况下,您可以传递一个参数并获取函数val f: Int => Int = multiply(2) _ f(2) // 4 f(3) // 6 f(525) // 1050 ,然后使用另一个参数调用它:

implicit val x = 2
def multiply(m: Int)(implicit n: Int): Int = m * n

multiply(5) //10

curried方法的真正强大之处在于第二个参数是隐含的,因此您不必明确地传递它。

OBJECT_LIBRARY = {'A': A(), 'B': B(), 'C': C()}
相关问题