Saturday, September 6, 2008

Tutorial 1: Hello World

Following the tradition, here is the code for a program printing "Hello world" in F#.
#light
open System
printfn "Hello world\n"
Console.ReadKey(true)


Below follows an explanation of each line.

#light
This tells the compiler we are using the lightweight syntax. Apparently the syntax of F# comes in several flavors. This syntax works well for me.

open System
This includes a library containing the function called at the end to wait for a key press.

printfn "Hello world\n"
Prints Hello world on the console.

Console.ReadKey(true)
Waits for a key press.

That was it for now. We have learned the bare minimum to do some simple text I/O. In the next tutorial we will see how to use functions to implement the Euler integration method.

2 comments:

Ayi said...

nice article,,
help me testing f# program,,
thanks~

Borys Niewiadomski said...

great stuff! just what I needed for my first step.