Trivial snippet of F# code does not work under MONO - f#

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.

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)

Related

F# on macOS - Fake fails to build

I am getting an error when trying to build a simple F# project on macOS High Sierra.
$ mono --version
Mono JIT compiler version 5.0.1.1 (2017-02/5077205 Sun Sep 17 18:29:46 BST 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: normal
SIGSEGV: altstack
Notification: kqueue
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen (concurrent by default)
Steps:
Open VS Code
Ionide New F# Project
Choose the Suave Project Template
$ mono .paket/paket.exe install
$ ./build.sh
The error is:
1) System.Exception: dotnet build failed
at FSI_0005.Build+runDotnet#40.Invoke (System.String message) [0x00001] in <c9993ec69ddb4848af99438005012ea7>:0
at Microsoft.FSharp.Core.PrintfImpl+StringPrintfEnv`1[TResult].Finalize () [0x00012] in <5893d081904cf4daa745038381d09358>:0
at Microsoft.FSharp.Core.PrintfImpl+Final1#224[TState,TResidue,TResult,A].Invoke (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] env, A a) [0x00038] in <5893d081904cf4daa745038381d09358>:0
at Microsoft.FSharp.Core.OptimizedClosures+Invoke#3253[T2,TResult,T1].Invoke (T2 u) [0x00001] in <5893d081904cf4daa745038381d09358>:0
at FSI_0005.Build.runDotnet (System.String workingDir, System.String args) [0x00048] in <c9993ec69ddb4848af99438005012ea7>:0
at FSI_0005.Build+clo#64-6.Invoke (System.String p) [0x0000a] in <c9993ec69ddb4848af99438005012ea7>:0
at Microsoft.FSharp.Collections.SeqModule.Iterate[T] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] action, System.Collections.Generic.IEnumerable`1[T] source) [0x0002d] in <5893d081904cf4daa745038381d09358>:0
at FSI_0005.Build+clo#62-5.Invoke (Microsoft.FSharp.Core.Unit _arg4) [0x0000b] in <c9993ec69ddb4848af99438005012ea7>:0
at Fake.TargetHelper+targetFromTemplate#209-1[a].Invoke (Microsoft.FSharp.Core.Unit unitVar0) [0x00001] in <59b649fdccf1c534a7450383fd49b659>:0
at Fake.TargetHelper.runSingleTarget (Fake.TargetHelper+TargetTemplate`1[a] target) [0x0004b] in <59b649fdccf1c534a7450383fd49b659>:0
How can I get this working?
Ionide did not pick the correct target framework by default.
You need to make the following changes:
To *.fsproj, change the target framework to:
<TargetFramework>netcoreapp2.0</TargetFramework>
To paket.dependencies, change the framework to:
framework: >= netcoreapp2.0
Run Paket again:
$ mono .paket/paket.exe install
Run the build script again:
$ ./build.sh

Finding linux version inside a device driver

I am new to linux device driver development. I am trying to write a simple hello world module that would display the version of kernel running on the system where I try to insert hello_world module into kernel.
I used LINUX_VERSION_CODE in version.h to get linux version and built the module.
When I try to insert the ko file on a different system other than where it was built, it still shows the version of kernel where it was built
I believe issue lies with using C macro.
Can someone help me how to find linux version of local machine where the ko is to be inserted instead of finding version of kernel where my module gets built
You're right - LINUX_VERSION_CODE is a macro that provides compile-time info about the version of the Linux headers that you're using to compile the module. The macro cannot have any knowledge about the version of the kernel that the module will actually be loaded into.
The utsname() function in <linux/utsname.h> provides a pointer to a new_utsname struct, which has sysname, release and version members that contain what you're looking for.
The information from these members is used in /proc/version, as shown in fs/proc/version.c :
static int version_proc_show(struct seq_file *m, void *v)
{
seq_printf(m, linux_proc_banner,
utsname()->sysname,
utsname()->release,
utsname()->version);
return 0;
}
linux_proc_banner is a string that is currently defined as follows :
const char linux_proc_banner[] =
"%s version %s"
" (" LINUX_COMPILE_BY "#" LINUX_COMPILE_HOST ")"
" (" LINUX_COMPILER ") %s\n";
On my system, reading /proc/version - and thus reading these members - results in obtaining the following string :
Linux version 4.1.6-1-ARCH (builduser#tobias) (gcc version 5.2.0 (GCC) ) #1 SMP PREEMPT Mon Aug 17 08:52:28 CEST 2015
Thus, sysname is Linux, release is 4.1.6-1-ARCH, and version is #1 SMP PREEMPT Mon Aug 17 08:52:28 CEST 2015.

How to get MonoDevelop to compile F# projects?

The problem seems to be as follows, there compiler puts in a redundant reference to an assembly. I have no idea how to avoid this, there doesn't seem to be any field in MonoDevelop build options where this would be coming from:
Building: FSharpPractice (Debug|x86)
Building Solution FSharpPractice
Building: FSharpPractice (Debug|x86)
Performing main compilation...
C:\Program Files\FSharp-2.0.0.0\bin\fsc.exe --noframework --nologo
--target:exe
--out:"C:\Users\Alex Limonov\Documents\Projects\FSharpPractice\bin\Debug\FSharpPractice.exe"
--noframework
--debug-
--optimize-
--tailcalls-
-r:C:\Program Files\FSharp-2.0.0.0\bin\FSharp.Core.dll
-r:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll
-r:"C:\Program Files\FSharp-2.0.0.0\bin\FSharp.Core.dll"
-r:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll"
C:\Users\Alex Limonov\Documents\Projects\FSharpPractice\Program.fs
Build complete -- 2 errors, 0 warnings
In my case (MonoDevelop 2.4.2 with F# binding 2.4 on Mac OS X 10.6) I managed to compile F# project once I've explicitly added a reference to FSharp.Core.dll (4.0.0.0 here).

Installing luasql 2.2 with luarocks onto lua for windows install

So it turns out lua for windows install has some earlier 2.1 version of luasql on it, and I need to be able to use luasql 2.2 (particularly mysql). I've spent all day trying to install this thing with luarocks but keep hitting a wall. This is the 3rd wall I've hit but the first one that I just have no clue where to even begin.
I run: luarocks install luasql-mysql MYSQL_DIR="E:/Programs/MySQL/MySQL Server 5.5"
It goes through and outputs (removing a lot of the output where it's just repeating the same thing but different file):
Extracting luasql-2.2.0\src\jdbc
Extracting luasql-2.2.0\src\jdbc\Makefile
... (lots of these here)
Extracting luasql-2.2.0\vc6\sqlite.def
Everything is Ok
Folders: 17
Files: 84
Size: 358091
Compressed: 440320
cl /MD /O2 -c -Fosrc/luasql.obj -IF:/Code/Lua/5.1/include src/luasql.c -IE:/Prog
rams/MySQL/MySQL Server 5.5/include
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
luasql.c
cl /MD /O2 -c -Fosrc/ls_mysql.obj -IF:/Code/Lua/5.1/include src/ls_mysql.c -IE:/
Programs/MySQL/MySQL Server 5.5/include
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
ls_mysql.c
e:\programs\mysql\mysql server 5.5\include\mysql_com.h(291) : error C2061: synta
x error : identifier 'SOCKET'
e:\programs\mysql\mysql server 5.5\include\mysql_com.h(337) : error C2059: synta
x error : '}'
... (lots of these here, same errors just different lines)
E:/Programs/MySQL/MySQL Server 5.5/include\mysql.h(374) : error C2143: syntax er
ror : missing '{' before '*'
E:/Programs/MySQL/MySQL Server 5.5/include\mysql.h(374) : fatal error C1003: err
or count exceeds 100; stopping compilation
Error: Build error: Failed compiling object src/ls_mysql.obj
Any idea where to start? I've had to a) install standalone mysql (was previously using one that came with WAMP since I was already using that before), and b) install visual studio 2010 (c# and c++ versions so far), and c) use visual studio command prompt to run the luarocks stuff, if I use regular command problem it breaks way before this.
I'm hoping this is an easy issue to fix for someone familiar with compiling C which is what this seems to be doing.
Add the following to ls_mysql.c after line 17:
#include <windows.h>
So that windows.h is included after winsock.h and before mysql.h.
References:
http://forums.mysql.com/read.php?45,37472,37472
C++ Redefinition Header Files (winsock2.h)

F# crashes on Mono 2.10

After reading some reports about the inadequacies of the Mono 2.6 garbage collector, I decided to give Mono 2.10 a go. I found that the 2.10 runtime crashes with the following simple F# program:
let rec f x acc =
if x = 0 then acc
else f (x - 1) (acc + 1)
f 10 0
Equivalent looping C# code runs just fine as does an F# hello world program. The F# code also works ok with Mono 2.6 and .Net. Can anyone else reproduce this? Is it a bug or is it just my installation?
Here are the various runtimes I've tried and results I got.
Mono 2.10.2 (compiled from sources on Debian Squeeze)
-- "Stack overflow: IP: 0x4153bb84, fault addr: (nil)"
Mono 2.8 (compiled from sources on Debian Squeeze)
-- "Native stacktrace: ..."
Mono 2.10.2 (Windows binary)
-- "mono.exe has stopped working" dialog.
Mono 2.10.2 (VMware image)
-- Segmentation fault
Mono 2.6.7 (bundled with Debian Squeeze)
-- Works fine
The F# compiler used was from the November 2010 CTP.
I've reported this problem as bug #693905 at https://bugzilla.novell.com/show_bug.cgi?id=693905.

Resources