F#

Appeared in:
2002
Influenced by:
Paradigm:
Typing discipline:
Versions and implementations (Collapse all | Expand all):
Programming language

F# is a high-level programming language which supports functional and object-oriented programming in addition to traditional procedural programming.

Elements of syntax:

Nestable comments (* ... *)

Examples:

Hello, World!:

Example for versions fsharp 2.0.0
printfn "Hello, World!"

Factorial:

Example for versions fsharp 2.0.0

This example uses recursive definition of factorial, expressed in procedural paradigm.

factorial defines the actual factorial-calculating routine, and printFact defines the routine that outputs calculated factorials in required format.

let rec factorial n =
    match n with
    | 0 -> 1
    | _ -> n * factorial (n - 1)

let rec printFact n  =
    match n with 
    | 0 -> printfn "0! = 1"
    | _ -> printFact (n-1)
           printfn "%d! = %d"  n (factorial (n))
           
printFact(16)

Fibonacci numbers:

Example for versions fsharp 2.0.0

This example uses straightforward recursive definition of Fibonacci numbers, expressed in procedural paradigm.

let rec fibonacci n =
    match n with
    | 1 | 2 -> 1
    | _ -> fibonacci (n-1) + fibonacci (n-2)

let rec printFib n  =
    match n with 
    | 1 -> printf "%d, " (fibonacci (n))
    | _ -> printFib (n-1)
           printf "%d, " (fibonacci (n))
           
printFib(16)
printfn "..."