some initial thoughts on F#
...after doing a handful of Project Euler problems:
Compiling/Running
So, F# is part of .NET, which means like Java it needs to have a bunch of project structure for the dotnet tool to compile it. I've tried to isolate the fsc compiler, but at least on my debian computer, it throws a bunch of errors if I try to compile a single file. There might be a workaround, but I let it go.
It turns out, you can run simple fsharp files as scripts using the fsharp interpreter. Those files must be .fsx files, and have the limitations of interpreted programs; can't use functions before they're instantiated, etc. The dotnet interpreter has a noticable startup lag, which is unfortunate.
dotnet fsi script.fsx
Syntax
it's... honestly just fine. I have a big gripe with the way functions
are declared: you must use the let keyword, same as variables, and
recursive functions must be labelled with let rec. Additionally, the
type signature can't be declared all at once; with the lack of commas,
you must parenthesize each parameter with its type if it's something the
compiler can't infer. This happens often with Euler, since you need to
use int64 for several problems. Example:
let rec productsDigitH (tot:int64) (num:int64) : int64 = // fn
what I would love to be able to do is something like this:
let rec productsDigitH tot num : int64 -> int64 -> int64 = // fn
Otherwise, the syntax is what you'd expect from a functional language. You can pipe results around using |>, and since F# interacts with .NET and isn't purely functional, you can drop a print statement in the middle of a function and it'll get evaluated imperatively. It has pattern matching.
I haven't had an excuse to mess with the dimensions, which are the part of the type system that really excited me. Maybe I'll need to look for something very specific to try that out. Maybe I break out my orbital mechanics textbook :)