F#語言入門之什麼是F#語言
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,不可變和可比較的,使它們非常容易使用。完整教程閱讀ofollow,noindex">http://nopapp.com/Blog/Article/FSharp-What-Is-FSharp