官术网_书友最值得收藏!

F# functions

F# functions act like variables. We can declare and use them in the same way as we use variables in C#. A function definition starts with the let keyword, followed by the function name and parameters, a colon, its type, and the right-side expression, showing what the function does. The syntax is follows:

Let functionName parameters [ : returnType] = functionbody

In the preceding syntax:

  • functionName is an identifier of the function.
  • parameters gives the list of parameters separated by spaces. We can also specify an explicit type for each parameter and if not specified, the compiler tends to presume it from the function body as variables.
  • functionbody comprises an expression, or a compound expression, which has number of expressions. The final expression in the function body is the return value.
  • returnType is a colon followed by a type and it is optional. If the returnType is not specified, then the compiler determines it from the final expression in the function body.

Have a look at the following example for our syntax: 

let addValue (x : int) = 5 + x
主站蜘蛛池模板: 北流市| 新和县| 沙洋县| 托克逊县| 威信县| 洪湖市| 长治市| 安岳县| 西华县| 乌拉特中旗| 如皋市| 宜川县| 清水河县| 阿合奇县| 永修县| 广河县| 扶余县| 黑水县| 巢湖市| 洛川县| 卓尼县| 共和县| 平乡县| 九江市| 安岳县| 巴中市| 水城县| 扶风县| 竹北市| 太保市| 司法| 汤原县| 兴山县| 高平市| 麻江县| 自贡市| 会同县| 荆门市| 东乌珠穆沁旗| 余干县| 娱乐|