Saturday, June 19, 2010

OO Hello World - F#

Hello world in F# is here.
F# is a great addition to the .NET set of languages because of its functional paradigm support.
You can go directly to the F# Info section to get some extra info about the language.

By the way, you can see my previous post here:
where I give some details on WHY these "OO Hello World series" samples.

Version 1 (Minimal):
The minimum you need to type to get your program compiled and running.
type Greet(name:string) = 
    member private = name.[0].ToString().ToUpper() + name.[1..]
    member self.Salute() = printfn "Hello %s!" name

// Greet the world!
 let g = Greet("world")

Version 2 (Verbose):
Explicitly adding instructions and keywords that are optional to the compiler.
namespace GreetProgram
open System

type Greet(name:string) = class
    member private = name.[0].ToString().ToUpper() + name.[1..]
    member public self.Salute() = printfn "Hello %s!"

// Greet the world!
module GreetModule =
    let g:Greet = new Greet("world")

The Program Output:

F# Info:

F# (pronounced “F Sharp”) is the latest addition to the Microsoft programming languages.
“F# is a succinct, expressive and efficient functional and object-oriented language for .NET which helps you write simple code to solve complex problems.” “F# brings you type safe, succinct, efficient and expressive functional programming language on the .NET platform. It is a simple and pragmatic language, and has particular strengths in data-oriented programming, parallel I/O programming, parallel CPU programming, scripting and algorithmic development. It lets you access a huge .NET library and tools base and comes with a strong set of Visual Studio development tools. F# combines the advantages of typed functional programming with a high-quality, well-supported modern runtime system.” Taken from (

“F# is a programming language that provides support for functional programming in addition to traditional object-oriented and imperative (procedural) programming. The Visual F# product provides support for developing F# applications and extending other .NET Framework applications by using F# code. F# is a first-class member of the .NET Framework languages and retains a strong resemblance to the ML family of functional languages.” Taken from: (

Current Version:
Developed by:
Don Syme
Influenced by:
OCaml (Xavier Leroy)
Predecessor Language
Predecessor Appeared
Predecessor Creator
Runtime Target:
Latest Framework Target:
Mono Target:
Allows Unmanaged Code:
Source Code Extension:
“.fs”, “.fsx”
Case Sensitive:
Free Version Available:
Open Source:
Latest IDE Support:
Visual Studio 2010 (std, pro, etc) or Visual Studio 2008 (std, pro, shell)
SharpDevelop 3.2/4.0 (beta)
MonoDevelop 2.2
Language Reference:
Extra Info:

No comments:

Post a Comment