English 中文(简体)
F# - Program Structure
  • 时间:2024-11-03

F# - Program Structure


Previous Page Next Page  

F# is a Functional Programming language.

In F#, functions work pke data types. You can declare and use a function in the same way pke any other variable.

In general, an F# apppcation 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 apppcations 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-pne comment *)
// This is a single-pne comment

let sign num =
   if num > 0 then "positive"
   epf 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 apppcation.

    The main loop contains the top executable statements.

Advertisements