Getting Started with F#

F# is a functional programming language, where a program is a series of bindings of expressions to identifiers. Here are some examples:

        let x = 3 + (4 * 5)
        let res = (if x = 23 then "correct" else "incorrect")

When executed this program would bind "x" to the value 23 and "res" to the string "correct". F# is not a "pure" functional language, so the evaluation of expressions may have side effects, e.g. I/O, mutating state, displaying graphics etc. Here is a simple F# console-based program:

        let main = System.Console.WriteLine("Hello World\n")

Here "main" not so much a function but rather a dummy value to hold the result of the computation on the right of the "=" symbol. If placed in a text file "hello.fs" then this program can be compiled as follows:

        > fsc hello.fs

and executed using

        > hello.exe

You may prefer to use the file extentsion "hello.ml". F# code can also be placed in a library, e.g. lib.fs may contain

        let MyLibFunction() = System.Console.WriteLine("Hello World\n")

and your hello.fs may simply contain

        let main = MyLibFunction()

which we would compile using:

        > fsc -a lib.fs
        > fsc -r lib.dll hello.fs

producing a lib.dll library and the hello.exe executable. Both of these are .NET assemblies. You could also compile your library and main program together to produce a single .NET assembly:

        > fsc -o hello.exe lib.fs hello.fs

This produces a single hello.exe executable. Typical projects will compile many F# files (e.g 30 or 40) into each assembly.