This is the code for a simple console project, that prints "Hello, World!" to STDOUT, and exits with an exit code of 0
[<EntryPoint>]
let main argv =
printfn "Hello, World!"
0
Example breakdown Line-by-line:
[<EntryPoint>]
- A .net Attribute that marks "the method that you use to set the entry point" of your program (source).let main argv
- this defines a function called main
with a single parameter argv
. Because this is the program entry point, argv
will be an array of strings. The contents of the array are the arguments that were passed to the program when it was executed.printfn "Hello, World!"
- the printfn
function outputs the string** passed as its first argument, also appending a newline.0
- F# functions always return a value, and the value returned is the result of the last expression in the function. Putting 0
as the last line means that the function will always return zero (an integer).** This is actually not a string even though it looks like one. It's actually a TextWriterFormat, which optionally allows the usage of statically type checked arguments. But for the purpose of a "hello world" example it can be thought of as being a string.