Computer Science Experimentation

Saturday, September 11, 2010

F#- Introduction

F# is a first class language in .NET and Visual Studio together with C#, VB and C++. Solutions are created and debugged in the same way. IntelliSense is available. Generated assembles can be used in the .NET solutions. Execution speed is equivalent to C#.

But, F# also has unique features as F# Interactive and F# Scripting Files. These features are attractive to scientific and engineering developers that are used to tools like Matlab or Python.

Installation

A free installation is available as follow:

1) Install .NET 4.0 from
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992&displaylang=en

2) Install Visual Studio Shell 10 from

http://www.microsoft.com/downloads/en/details.aspx?familyid=8E5AA7B6-8436-43F0-B778-00C3BCA733D3&displaylang=en

3) Install F# 2.0 from

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=f8c623ae-aef6-4a06-a185-05f59be47d67&displaylang=en

4) Add extra content from:

http://fsharppowerpack.codeplex.com/releases/view/40168

Using F# Interactive

In order to open an interactive session, start the following executable:

C:\Program Files (x86)\Microsoft F#\v4.0\fsi.exe

Interactive session is also available inside Visual Studio. You can be shown it with ‘View/Other Windows/F# Interactive’.

Using F# Script Files

Script files have extension ‘.fsx’. You can create them with Notepad. By right-clicking on Windows Explorer, you can execute it by selecting “Run with F# Interactive”. This will start the script file with FSI.

Using Visual Studio to create script files has the advantage of IntelliSense. Create an script by using ‘File/New/File/F# Script File’.

Compiling F#

In order to generate an executable or a library, create a ‘.fs’ file in Notepad and use it with:

C:\Program Files\Microsoft F#\v4.0\fsc.exe

Using Visual Studio to create source files has the advantage of IntelliSense and easy reference to other assembles and .NET resources. Create a project by using ‘File/New/Project/F# Application or F# Library’.

Using Source File and Interactive

Code can be entered in Visual Studio source file. You can transfer and execute sections of the code by marking it and pressing ‘Alt+Enter’. This is a method to debug the code, traditionally used by systems with interactive capability.

No comments:

Post a Comment