F#函數(shù)式編程語言
F#是由微軟發(fā)展的為微軟.NET語言提供運(yùn)行環(huán)境的程序設(shè)計(jì)語言,是函數(shù)編程語言(FP,F(xiàn)unctional Programming),函數(shù)編程語言最重要的基礎(chǔ)是Lambda Calculus。它是基于OCaml的,而OCaml是基于ML函 數(shù)程式語言。有時F# 和 OCaml 的程式是可以交互編譯的。
F#已經(jīng)接近成熟,支援Higher-Order Function、Currying、Lazy Evaluation、Continuations、Pattern Matching、Closure、List Processing、Meta-Programming。這是一個用于顯示.NET在不同編程語言間互通的程序設(shè)計(jì),可以被.NET中的任意其它代碼編 譯和調(diào)用。
F#將被集成在Visual Studio 2010中,含有對.Net Framework的完全支持。
一些小小范例如下:
(* 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)
評論
圖片
表情
