I continue to march down the F# path and so far so good. The brain hurts a little bit, but that's to be expected. After looking at LAMP and C++ all day at work, switching to Mono/.NET/C#/F# takes an abrupt neural rewiring.
Over the past few days I hit a few stumbling blocks working through some examples in Expert F# and bypassed them for the moment. The first was I could not get a sequence expression (seq { ... }) to work for the life of me in fsi. Later, I could not get some simple .NET I/O such as File.ReadAllLines to work at all (a somewhat disconcerting "error: convMethodRef: could not bind to method"). Last issue first: why can't the F# interpreter find standard .NET System.IO functionality?
A quick C# program to try and figure out what's going on:
using System;
using System.IO;public class Test {
public static void Main() {
string[] lines = File.ReadAllLines("test.dat");
foreach (string s in lines) {
Console.WriteLine(s);
}
}
}
And of course mcs fails with a telltale error:
$ mcs Test.cs
Test.cs(6,26): error CS0117: `System.IO.File' does not contain a definition for `ReadAllLines'
/Library/Frameworks/Mono.framework/Versions/1.2.6/lib/mono/1.0/mscorlib.dll (Location of the symbol related to previous error)
Compilation failed: 1 error(s), 0 warnings
A little digging and it turns out gmcs invokes the .NET 2.0 world and this is where the missing functionality lives. It's never this easy of course, since the F# interpreter (fsi) seems to be stuck pointing to the .NET 1.x world. After more digging I found a thread on hubFS that discusses this very problem and a resolution. Everything (so far) that was broken now works fine... except for some reason running fsi-old.exe messes with my terminal and now I need to ctrl-h to backspace. Another issue to resolve on some other day.
It is going to take some time to get comfortable with this unfamiliar world.
Comments