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

The Hello World example

No book is complete without some quintessential Hello World examples. So here it is:

printfn "Hello World";;

Yes, this is all you need. Notice the terseness, simplicity, and lack of clutter. Now let's run this in the F# interactive environment. In order to run it, you would need to have ";;" at the end of the statement. We will provide more details on this interactive environment setup later in Chapter 2, Now Lazily Get Over It, Again.

This is the response that you see when you run the preceding line of code. It is a minimal viable example; however these attributes of simplicity, terseness, and simplification extend beyond HelloWorld samples as you will see.

Let's look at a simple function, square. You can write a function in F# as follows:

let square = fun n -> n * n

Or you can write it in a simpler syntax like the next one. Notice the first-class citizenship in action here:

let square n = n * n

When this function is executed in F# interactive, you can immediately see the results upon invocation as in the following screenshot:

主站蜘蛛池模板: 神木县| 洞口县| 招远市| 左贡县| 西和县| 两当县| 宜宾县| 金沙县| 台前县| 海林市| 孝义市| 北票市| 浪卡子县| 钟祥市| 勃利县| 张掖市| 茂名市| 庐江县| 麦盖提县| 丹江口市| 聂荣县| 横峰县| 神木县| 徐闻县| 府谷县| 平顺县| 太康县| 河池市| 普兰县| 顺义区| 商丘市| 稻城县| 错那县| 会东县| 历史| 平邑县| 阳朔县| 岑溪市| 惠水县| 米林县| 始兴县|