F#是一种函数式编程语言,可以轻松编写正确且可维护的代码。
F#编程主要涉及定义类型推断和自动泛化的类型和函数。 这使您可以将焦点保留在问题域上并操纵其数据,而不是编程的细节。
open System // Gets access to functionality in System namespace. // Defines a function that takes a name and produces a greeting. let getGreeting name = sprintf "Hello, %s! Isn't F# great?" name [<EntryPoint>] let main args = // Defines a list of names let names = [ "Don"; "Julia"; "Xi" ] // Prints a greeting for each name! names |> List.map getGreeting |> List.iter (fun greeting -> printfn "%s" greeting) 0
F#有许多功能,包括:
- 轻量级语法
- 默认不变
- 类型推断和自动泛化
- 一流的功能
- 强大的数据类型
- 模式匹配
- 异步编程
丰富的数据类型
记录和识别联合等数据类型允许您表示复杂的数据和域。
// Group data with Records type SuccessfulWithdrawal = { Amount: decimal Balance: decimal } type FailedWithdrawal = { Amount: decimal Balance: decimal IsOverdraft: bool } // Use discriminated unions to represent data of 1 or more forms type WithdrawalResult = | Success of SuccessfulWithdrawal | InsufficientFunds of FailedWithdrawal | CardExpired of System.DateTime | UndisclosedFailure
F#记录和区分联合在默认情况下是非null,不可变和可比较的,使它们非常容易使用。完整教程阅读http://nopapp.com/Blog/Article/FSharp-What-Is-FSharp