In F#, functions work like data types. You can declare and use a function in the same way as any other variable.
You can define a simple F# program that prints text on the console in the following different ways.
An F# application does not have any specific entry point. The compiler executes all top-level statements in the file from top to bottom.
You can use printfn
to print a text message on a console without using any entry point, as shown below.
printfn "Welcome to F# Tutorial."
You can also print a text message on the console using Console.WriteLine
by including the System
namespace.
open System;
Console.WriteLine("Welcome to F# Tutorial.")
You can also call the printfn
inside a class as shown in the below example.
type Program() =
class
do printfn "Welcome to F# Tutorial."
end
new Program()
The printfn
can be used inside a function, as shown in the below example.
let myFunc = printfn "Welcome to F# Tutorial."
myFunc
To follow procedural programming style, many applications keep a single top-level statement that calls the main loop as shown below.
open System
let message = "Welcome to F# Tutorial."
[<EntryPoint>]
let main argv =
Console.WriteLine(message)
0 // return an integer exit code
open
statements that are used to import namespaces.