我们知道,F# 2.0 有面向 .NET Framework 2.0 和 .NET Framework 4 的两个运行时。此外,F# 2.0 还有一个面向 Silverlight 的运行时。
面向 .NET Framework 2.0 的 F# 2.0 运行时的核心库 (FSharp.Core.dll) 将一些 API 包含在 System 命名空间中,这些 API 与 F# 开发所需的 .NET Framework 4 API 相同。例如 System.Numerics.BigInteger 和 System.Tuple 就是这样。
Windows 操作系统:
E:\> gacutil -l FSharp.Core
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.1
版权所有(C) Microsoft Corporation。保留所有权利。
全局程序集缓存包含下列程序集:
FSharp.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
项目数 = 2
E:\> fsi.exe
Microsoft(R) F# 2.0 Interactive 版本 4.0.30319.1
版权所有(C) Microsoft Corporation。保留所有权利。
若要获得帮助,请键入 #help;;
> 8I.GetType().AssemblyQualifiedName;;
val it : string =
"System.Numerics.BigInteger, System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
> #quit;;
E:\> c:
C:\> cd "\Program Files\Reference Assemblies\Microsoft\FSharp\2.0\Runtime"
C:\Program Files\Reference Assemblies\Microsoft\FSharp\2.0\Runtime> dir v2.0\FSharp.Core.dll v4.0\FSharp.Core.dll
驱动器 C 中的卷是 OS
卷的序列号是 5ACA-EDB5
C:\Program Files\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v2.0 的目录
2010/03/19 05:52 938,840 FSharp.Core.dll
1 个文件 938,840 字节
C:\Program Files\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v4.0 的目录
2010/03/19 05:52 895,832 FSharp.Core.dll
1 个文件 895,832 字节
0 个目录 4,724,301,824 可用字节
C:\Program Files\Reference Assemblies\Microsoft\FSharp\2.0\Runtime>
Linux 操作系统:
ben@ben-1520:~$ gacutil -l FSharp.Core
The following assemblies are installed into the GAC:
FSharp.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Number of items = 1
ben@ben-1520:~$ fsi.exe
Microsoft (R) F# 2.0 Interactive build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> 8I.GetType().AssemblyQualifiedName;;
val it : string =
"System.Numerics.BigInteger, FSharp.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
> #quit;;
- Exit...
ben@ben-1520:~$ cd /usr/local/bin/FSharp-2.0.0.0/bin/ && ls -l FSharp.Core.dll
-rw-r--r-- 1 root root 938,840 2010-06-14 23:54 FSharp.Core.dll
ben@ben-1520:/usr/local/bin/FSharp-2.0.0.0/bin$
使用 .NET Reflector 来查看:
让我们琮看看下面的 test.fs 程序:
1: open System;
2: printfn "OS Version: %A" Environment.OSVersion
3: printfn "CLR Version: %A" Environment.Version
4: printfn "%s" (8I.GetType().AssemblyQualifiedName)
在 Linux 操作系统下编译和运行(使用面向 .NET Framework 2.0 的 F# 2.0 运行时):
ben@ben-1520:~/work$ fsc.exe test.fs
Microsoft (R) F# 2.0 Compiler build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
ben@ben-1520:~/work$ fsc.exe --out:test2.exe --standalone test.fs
Microsoft (R) F# 2.0 Compiler build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
ben@ben-1520:~/work$ ls -l test*.exe
-rwxr-xr-x 1 ben ben 923,136 2010-08-15 14:25 test2.exe
-rwxr-xr-x 1 ben ben 4,608 2010-08-15 14:25 test.exe
ben@ben-1520:~/work$ ./test.exe
OS Version: Unix 2.6.32.24
CLR Version: 2.0.50727.1433
System.Numerics.BigInteger, FSharp.Core, Version=2.0.0.0 , Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
ben@ben-1520:~/work$ ./test2.exe
OS Version: Unix 2.6.32.24
CLR Version: 2.0.50727.1433
System.Numerics.BigInteger, test2, Version=0.0.0.0 , Culture=neutral, PublicKeyToken=null
ben@ben-1520:~/work$
上面的 test2.exe 使用 --standalone 参数编译,表示以静态方式将 F# 库与依赖于此库的所有引用的 DLL 链接到所生成的程序集中。可以看出,在 test.exe 程序中,System.Numerics.BigInteger 是定义中 FSharp.Core 程序集中,而在 test2.exe 中,System.Numerics.BigInteger 被链接到生成的 test2 程序集中。
在 Windows 操作系统下编译和运行(使用面向 .NET Framework 4 的 F# 2.0 运行时):
E:\work> fsc.exe test.fs
Microsoft(R) F# 2.0 编译器版本 4.0.30319.1
版权所有(C) Microsoft Corporation。保留所有权利。
E:\work> fsc.exe --out:test2.exe --standalone test.fs
Microsoft(R) F# 2.0 编译器版本 4.0.30319.1
版权所有(C) Microsoft Corporation。保留所有权利。
E:\work> dir test*.exe
驱动器 E 中的卷是 Data2
卷的序列号是 16BB-989E
E:\work 的目录
2010/08/15 14:29 5,120 test.exe
2010/08/15 14:30 880,128 test2.exe
2 个文件 885,248 字节
0 个目录 51,641,475,072 可用字节
E:\work> test.exe
OS Version: Microsoft Windows NT 6.0.6002 Service Pack 2
CLR Version: 4.0.30319.1
System.Numerics.BigInteger, System.Numerics, Version=4.0.0.0 , Culture=neutral, PublicKeyToken=b77a5c561934e089
E:\work> test2.exe
OS Version: Microsoft Windows NT 6.0.6002 Service Pack 2
CLR Version: 4.0.30319.1
System.Numerics.BigInteger, System.Numerics, Version=4.0.0.0 , Culture=neutral, PublicKeyToken=b77a5c561934e089
E:\work>
可能看出,使用面向 .NET Framework 4 的 F# 2.0 运行时,System.Numerics.BigInteger 是 .NET Framework 4 的一部分,位于 System.Numerics 程序集中。不管是否使用 --standalone 参数编译,都不会改变这一点。
此外,IronRuby 以及 IornPython 也分成面向 .NET Framework 2.0 和 .NET Framework 4 两个版本。
参考资料
F# 可再发行组件包
Microsoft F# Developer Center
F# Downloads
Wikipedia: F Sharp (programming language)