浅谈 F# 2.0 的两个运行时

来源:互联网 发布:淘宝日本直邮是真的吗 编辑:程序博客网 时间:2024/05/21 03:16

我们知道,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.CoreMicrosoft (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项目数 = 2E:\> fsi.exeMicrosoft(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.CoreThe following assemblies are installed into the GAC:FSharp.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aNumber of items = 1ben@ben-1520:~$ fsi.exeMicrosoft (R) F# 2.0 Interactive build 2.0.0.0Copyright (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.dllben@ben-1520:/usr/local/bin/FSharp-2.0.0.0/bin$ 

 

使用 .NET Reflector 来查看:

 

让我们琮看看下面的 test.fs 程序:

1:  open System;2:  printfn "OS  Version: %A" Environment.OSVersion3:  printfn "CLR Version: %A" Environment.Version4:  printfn "%s" (8I.GetType().AssemblyQualifiedName)

在 Linux 操作系统下编译和运行(使用面向 .NET Framework 2.0 的 F# 2.0 运行时):

ben@ben-1520:~/work$ fsc.exe test.fsMicrosoft (R) F# 2.0 Compiler build 2.0.0.0Copyright (c) Microsoft Corporation. All Rights Reserved.ben@ben-1520:~/work$ fsc.exe --out:test2.exe --standalone test.fsMicrosoft (R) F# 2.0 Compiler build 2.0.0.0Copyright (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.exeben@ben-1520:~/work$ ./test.exeOS  Version: Unix 2.6.32.24CLR Version: 2.0.50727.1433System.Numerics.BigInteger, FSharp.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aben@ben-1520:~/work$ ./test2.exeOS  Version: Unix 2.6.32.24CLR Version: 2.0.50727.1433System.Numerics.BigInteger, test2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=nullben@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.fsMicrosoft(R) F# 2.0 编译器版本 4.0.30319.1版权所有(C) Microsoft Corporation。保留所有权利。E:\work> fsc.exe --out:test2.exe --standalone test.fsMicrosoft(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.exe2010/08/15  14:30           880,128 test2.exe               2 个文件        885,248 字节               0 个目录 51,641,475,072 可用字节E:\work> test.exeOS  Version: Microsoft Windows NT 6.0.6002 Service Pack 2CLR Version: 4.0.30319.1System.Numerics.BigInteger, System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089E:\work> test2.exeOS  Version: Microsoft Windows NT 6.0.6002 Service Pack 2CLR Version: 4.0.30319.1System.Numerics.BigInteger, System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089E:\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 两个版本。

0 0
原创粉丝点击