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

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
主站蜘蛛池模板: 九江县| 柳江县| 阿荣旗| 牟定县| 文成县| 揭西县| 望都县| 深泽县| 时尚| 北川| 丽江市| 浦北县| 登封市| 雷州市| 宁海县| 内丘县| 始兴县| 林口县| 武隆县| 西峡县| 卓资县| 泗水县| 改则县| 阿拉善右旗| 永和县| 娄底市| 卢龙县| 鄂托克前旗| 昌都县| 滁州市| 嘉鱼县| 卫辉市| 大渡口区| 体育| 鱼台县| 云梦县| 保靖县| 汝南县| 德格县| 会理县| 武夷山市|