F#
F# 语言在2010年6月编程语言排行榜中排名第四十五位。下面就是 GregorianTest.fs 程序:
1: let dt = System.DateTime(1582, 10, 4)
2: printfn "%s" (dt.ToString("dddd yyyy-MM-dd"))
3: printfn "%s" (dt.AddDays(1.0).ToString("dddd yyyy-MM-dd"))
2: printfn "%s" (dt.ToString("dddd yyyy-MM-dd"))
3: printfn "%s" (dt.AddDays(1.0).ToString("dddd yyyy-MM-dd"))
安装 F# 编译器:
ben@ben-1520:~/work$ wget http://download.microsoft.com/
download/1/3/B/13BE2B98-E487-4032-9441-22D4D2F4FAAC/fsharp.zip
ben@ben-1520:~/work$ sudo unzip -q fsharp.zip -d /usr/local/bin/
ben@ben-1520:~/work$ rm fsharp.zip
ben@ben-1520:~/work$ cd /usr/local/bin/FSharp-2.0.0.0
ben@ben-1520:/usr/local/bin/FSharp-2.0.0.0$ sudo chmod +x install-mono.sh
ben@ben-1520:/usr/local/bin/FSharp-2.0.0.0$ sudo wget http://anonsvn.mono-project.com/
source/trunk/mcs/class/mono.snk
ben@ben-1520:/usr/local/bin/FSharp-2.0.0.0$ sudo ./install-mono.sh
-- Resigning FSharp.Core.dll with mono.snk
Assembly bin/FSharp.Core.dll signed.
-- Installing FSharp DLLS into the GAC
Installed bin/FSharp.Core.dll into the gac (/usr/lib/mono/gac)
ben@ben-1520:/usr/local/bin/FSharp-2.0.0.0$ cd ~/work
ben@ben-1520:~/work$ cat >> ~/.bashrc <<!
>
> # set PATH for Microsoft F#
> if [ -d "/usr/local/bin/FSharp-2.0.0.0/bin" ] ; then
> PATH="/usr/local/bin/FSharp-2.0.0.0/bin:\$PATH"
> fi
> !
ben@ben-1520:~/work$ exit
download/1/3/B/13BE2B98-E487-4032-9441-22D4D2F4FAAC/fsharp.zip
ben@ben-1520:~/work$ sudo unzip -q fsharp.zip -d /usr/local/bin/
ben@ben-1520:~/work$ rm fsharp.zip
ben@ben-1520:~/work$ cd /usr/local/bin/FSharp-2.0.0.0
ben@ben-1520:/usr/local/bin/FSharp-2.0.0.0$ sudo chmod +x install-mono.sh
ben@ben-1520:/usr/local/bin/FSharp-2.0.0.0$ sudo wget http://anonsvn.mono-project.com/
source/trunk/mcs/class/mono.snk
ben@ben-1520:/usr/local/bin/FSharp-2.0.0.0$ sudo ./install-mono.sh
-- Resigning FSharp.Core.dll with mono.snk
Assembly bin/FSharp.Core.dll signed.
-- Installing FSharp DLLS into the GAC
Installed bin/FSharp.Core.dll into the gac (/usr/lib/mono/gac)
ben@ben-1520:/usr/local/bin/FSharp-2.0.0.0$ cd ~/work
ben@ben-1520:~/work$ cat >> ~/.bashrc <<!
>
> # set PATH for Microsoft F#
> if [ -d "/usr/local/bin/FSharp-2.0.0.0/bin" ] ; then
> PATH="/usr/local/bin/FSharp-2.0.0.0/bin:\$PATH"
> fi
> !
ben@ben-1520:~/work$ exit
fsi.exe 是 F# 交互窗口,fsc.exe 是 F# 编译器:
ben@ben-1520:~/work$ fsi.exe
Microsoft (R) F# 2.0 Interactive build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> System.Environment.OSVersion;;
val it : System.OperatingSystem =
Unix 2.6.32.22 {Platform = Unix;
ServicePack = "";
Version = 2.6.32.22;
VersionString = "Unix 2.6.32.22";}
> #quit;;
- Exit...
ben@ben-1520:~/work$ fsc.exe GregorianTest.fs
Microsoft (R) F# 2.0 Compiler build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
ben@ben-1520:~/work$ ./GregorianTest.exe
星期一 1582-10-04
星期二 1582-10-05
ben@ben-1520:~/work$
Microsoft (R) F# 2.0 Interactive build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> System.Environment.OSVersion;;
val it : System.OperatingSystem =
Unix 2.6.32.22 {Platform = Unix;
ServicePack = "";
Version = 2.6.32.22;
VersionString = "Unix 2.6.32.22";}
> #quit;;
- Exit...
ben@ben-1520:~/work$ fsc.exe GregorianTest.fs
Microsoft (R) F# 2.0 Compiler build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
ben@ben-1520:~/work$ ./GregorianTest.exe
星期一 1582-10-04
星期二 1582-10-05
ben@ben-1520:~/work$
运行结果和 GregorianTest.cs 的一样。但 F# 源程序比 C# 源程序更简洁。
