learn_F#

什么是F#?

F#是一门同样基于.net生态的语言,在某方面来讲,它与C#十分相似。

它与C#最大的不同,就是F#具有浓重的函数式思想,而C#则更多面向对象。

所有C#可以做的事情,F#都可以完成,区别只是要花费的精力有所不同。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// For more information see https://aka.ms/fsharp-console-apps
printfn "Hello from F#"
open System // Gets access to functionality in System namespace.

// Defines a list of names
let names = [ "Peter"; "Julia"; "Xi" ]

// Defines a function that takes a name and produces a greeting.
let getGreeting name = $"Hello, {name}"

// Prints a greeting for each name!
names
|> List.map getGreeting
|> List.iter (fun greeting -> printfn $"{greeting}! Enjoy your F#")

for cnt = 1 to 12 do
printf $"nice to see you ,{cnt} \n"

let mutable cnt = 0;//F#中let默认生成的值是自动绑定的,也就是不可变值,假如想要让let的值可变,那么就用mutable属性来修饰。
for name in names do
cnt <- cnt + 1
printfn $"hello ,No.{cnt} Are you {name}?"