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

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:

主站蜘蛛池模板: 新密市| 大足县| 唐河县| 常德市| 大埔区| 喀喇沁旗| 泗水县| 大姚县| 宁夏| 清新县| 阳泉市| 黄浦区| 钟祥市| 琼海市| 城市| 房产| 墨竹工卡县| 兴仁县| 蒲城县| 安多县| 郁南县| 安达市| 久治县| 南投市| 小金县| 尤溪县| 英吉沙县| 澄江县| 会昌县| 阳城县| 贵州省| 永康市| 永福县| 泽州县| 连州市| 大城县| 南岸区| 嫩江县| 腾冲县| 广灵县| 灌云县|