Archives

Getting Started with F# (Part I)

Hi, now i’m learning new programming language from .NET Framework, it’s F#. This new language is different from other .NET languages such as C# or VB. F# is designed to be simple yet powerful.

If we learn a new programming language, first step to do is how to print “hello world” :) and how to create it is quite simple.

Example below is code of hello world program. open System is similar to include in C#, open System is essential if we’re going to use function like Console.WriteLine or Console.ReadKey. To ending an expression, F# uses whitespace instead semicolon(;). To describe a function in F# we use keyword let and character “_’ is the name of main function in F#.

To print “hello world” message in console we use Console.WriteLine “hello world” and for preventing console window closing automatically we use Console.ReadKey().

open System
let _ =
Console.WriteLine "hello world"
Console.ReadKey()

This is an example for creating function and simple addition. There’s function called add. In add function we have two parameters x and y. Function in F# don’t declare its parameters or return value explicitly.