内容简介:Function 為 Haskell 最重要的元素,首先來看 Haskell 如何定義 function,也順便複習 F# 、ECMAScript 與 C#。GHC 8.4.3F# 與 Haskell 已經非常類似:
Function 為 Haskell 最重要的元素,首先來看 Haskell 如何定義 function,也順便複習 F# 、ECMAScript 與 C#。
Version
GHC 8.4.3
Haskell
foo x y = x + y too = \x y -> x + y
-
直接定義
foofunction,parameter 以 space 隔開,而 parameter 與 body 之間以=隔開 -
使用 Lambda Function,Haskell 規定一開始用
\表示 Lambda Function,而 parameter 與 body 之間以->隔開
FSharp
let foo x y = x + y let too = fun x y -> x + y
F# 與 Haskell 已經非常類似:
-
直接定義
foofunction,一開始使用let,之後寫法與 Haskell 相同 -
使用 Lambda Function,F# 規定一開始使用
fun,之後寫法與 Haskell 相同
ECMAScript
const foo = function (x, y) {
return x + y;
};
const too = (x, y) => x + y;
- ES5 使用 Anonymous Function 定義 function
- ES6 使用 Arrow Function 表示定義 function
CSharp
Func<int, int, int> foo = (x, y) => x + y; int too(int x, int y) => x + y;
- C# 3 使用 Func 使用 Delegate 定義 function
- C# 7 使用 Local Function 定義 fuction
Conclusion
- 各語言間只是語法稍有差異,但使用 function 的觀念都是相同的
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Out of their Minds
Dennis Shasha、Cathy Lazere / Springer / 1998-07-02 / USD 16.00
This best-selling book is now available in an inexpensive softcover format. Imagine living during the Renaissance and being able to interview that eras greatest scientists about their inspirations, di......一起来看看 《Out of their Minds》 这本书的介绍吧!