在MONO下,F#代码的简单片段不起作用

Joe*_*uha 5 mono f# f#-3.0

以下是一些不会因复杂性而获奖的代码:

[<EntryPoint>]
let main argv =
   let i = 1I
   printfn "One is %A\n" i
   0 // return an integer exit code
Run Code Online (Sandbox Code Playgroud)

它的编译如下:"c:/ Program Files(x86)/ Microsoft SDKs/F#/ 3.0/Framework/v4.0/Fsc.exe"--out:numericstest.exe --debug:full --target:exe - - standalone Program.fs

在Windows下,它会产生预期的结果.但是根据在Ubuntu下编译的Mono 3.0.7,它反而说:

mono numericstest.exe

Unhandled Exception: System.InvalidProgramException: Invalid IL code in System.Numerics.BigInteger:get_One (): method body is empty.

at Program.main (System.String[] argv) [0x00000] in <filename unknown>:0[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in System.Numerics.BigInteger:get_One (): method body is empty.

at Program.main (System.String[] argv) [0x00000] in <filename unknown>:0
Run Code Online (Sandbox Code Playgroud)

我做错了什么?非常感谢.

Jac*_* P. 2

您的代码没有任何问题——无论如何,该异常都是由您的代码引起的。您的机器上的组件似乎有问题System.Numerics.dll;要么它没有正确安装,要么它被错误地编译(例如,由 Mono C# 编译器),要么它正在执行某种类型转发,但它没有像应有的那样工作,等等。

如果您在不使用 BigInteger(通过后缀)的情况下运行代码会发生什么I


我在 VirtualBox 下运行的 Ubuntu(12.04,32 位)VM 中尝试了您的代码。代码按预期编译并运行。如果需要的话,这是输出:

编译/运行

jack@jack-linux:~/Desktop$ fsharpc --out:JoeHuha.exe --debug:full --target:exe --standalone JoeHuha.fs
F# Compiler for F# 3.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License
jack@jack-linux:~/Desktop$ mono JoeHuha.exe
One is 1
Run Code Online (Sandbox Code Playgroud)

单声道版本信息

jack@jack-linux:~/Desktop$ mono -V
Mono JIT compiler version 3.0.5 (master/1643364 Fri Feb 22 19:31:07 EST 2013)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  x86
    Disabled:      none
    Misc:          softdebug 
    LLVM:          supported, not enabled.
    GC:            Included Boehm (with typed GC and Parallel Mark)
Run Code Online (Sandbox Code Playgroud)

  • 我想知道这是否与以下事实有关:对于某些 .Net 版本,F# 使用自己的 Numerics.dll,而在其他版本中,它使用系统版本,并且您会在独立版本中得到一些奇怪的交互。 (2认同)