Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trivial snippet of F# code does not work under MONO

Tags:

mono

f#

f#-3.0

Here is a bit of code that won't win awards for complexity:

[<EntryPoint>]
let main argv =
   let i = 1I
   printfn "One is %A\n" i
   0 // return an integer exit code

It's compiled as follows: "c:/Program Files (x86)/Microsoft SDKs/F#/3.0/Framework/v4.0/Fsc.exe" --out:numericstest.exe --debug:full --target:exe --standalone Program.fs

Under Windows it produces the expected result. However under Mono 3.0.7 compiled under Ubuntu it instead says:

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

What am I doing wrong please? Many thanks.

like image 450
Joe Huha Avatar asked Nov 03 '22 23:11

Joe Huha


1 Answers

There's nothing wrong with your code -- that exception is due to your code anyway. It looks like there's something wrong with the System.Numerics.dll assembly on your machine; either it's not installed correctly, it's getting compiled incorrectly (e.g., by the Mono C# compiler), or it's doing some kind of type forwarding which is not working like it should, etc.

What happens if you run the code without using BigInteger (via the I suffix)?


I tried your code in my Ubuntu (12.04, 32-bit) VM running under VirtualBox. The code compiled and ran as expected. Here's the output if you want:

Compile/Run

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

Mono version info

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)
like image 149
Jack P. Avatar answered Nov 10 '22 03:11

Jack P.