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

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
主站蜘蛛池模板: 那坡县| 定兴县| 仁怀市| 临汾市| 巴林右旗| 阿城市| 鹤壁市| 锦州市| 广平县| 师宗县| 徐汇区| 星子县| 古田县| 江门市| 靖远县| 黔西县| 崇礼县| 武宣县| 吉林省| 耿马| 应城市| 建平县| 红安县| 桃江县| 大厂| 溧阳市| 通化县| 宜宾市| 山丹县| 临江市| 仙居县| 靖安县| 云安县| 南昌市| 桦甸市| 沙河市| 牡丹江市| 静安区| 锡林浩特市| 常熟市| 越西县|