পৃষ্ঠাসমূহ

.

Search Your Article

Total Pageviews

Wednesday, February 1, 2017

F# - Program Structure

F# is a Functional Programming language.
In F#, functions work like data types. You can declare and use a function in the same way like any other variable.
In general, an F# application does not have any specific entry point. The compiler executes all top-level statements in the file from top to bottom.

However, to follow procedural programming style, many applications keep a single top level statement that calls the main loop.
The following code shows a simple F# program −
open System
(* This is a multi-line comment *)
// This is a single-line comment

let sign num =
   if num > 0 then "positive"
   elif num < 0 then "negative"
   else "zero"

let main() =
   Console.WriteLine("sign 5: {0}", (sign 5))

main()
When you compile and execute the program, it yields the following output −
sign 5: positive
Please note that −
  • An F# code file might begin with a number of open statements that is used to import namespaces.
  • The body of the files includes other functions that implement the business logic of the application.
  • The main loop contains the top executable statements.

No comments:

Post a Comment