F♯

F♯

F#是由微軟發展的為.NET語言提供運行環境的程式設計語言,是函式程式語言FP,Functional Programming),函式程式語言最重要的基礎是Lambda Calculus。它是基於OCaml的,而OCaml是基於ML函式程式語言。有時F#和OCaml的程式是可以互動編譯的。

基本介紹

簡介,範例,

簡介

啟發語言:ML,OCaml,C#,Python,Haskell,Scala,Erlang.
F#已經接近成熟,支持高階函式、柯里化惰性求值、Continuations、模式匹配、閉包、列表處理和元編程。這是一個用於顯示.NET在不同程式語言間互通的程式設計,可以被.NET中的任意其它代碼編譯和調用。
2002年微軟開始由Don Syme帶領研發F#,從C#,LINQHaskell中獲取了經驗,2005年推出第一個版本,2007年7月31日釋出1.9.2.9版。2007年底,微軟宣布F#進入產品化的階段。
F#已被集成在Visual Studio2010中,版本是2.0,含有對.Net Framework的完全支持。
F#在Visual Studio2015中,版本是4.0。
F#在Visual Studio2017中,版本是4.1。

範例

一些小小範例如下:
(* This is a comment *)
(* Sample hello world program *)
printf "Hello World!"
#light
open Microsoft.FSharp.Collection.List
(* print a list of numbers recursively *)
let rec printlist l =
    (* When using "#light", you must indent with 4 spaces *)
    if l = [] then
    else
        printf "%d\n" (nth l 0)
        printlist (tl l)
#light
(* Sample Windows Forms Program *)
(* We need to open the Windows Forms library *)
open System.Windows.Forms
(* Create a window and set a few properties *)
let form = new Form(Visible=true, TopMost=true, Text="Welcome to F#")
(* Create a label to show some text in the form *)
let label =
    let temp = new Label()
    let x = 3 + (4 * 5)
    (* Set the value of the Text*)
    temp.Text <- x
    (* Remember to return a value! *)
    temp
(* Add the label to the form *)
do form.Controls.Add(label)
(* Finally, run the form *)
do Application.Run(form)
F#兼容於XNA Game Studio Express產品,可允許在Xbox 360上建構遊戲軟體。

熱門詞條

聯絡我們