Jun 26

F# Tool Support

F# runs on the .NET platform. This means that nearly all the major tools for the platform can be easily reused for F# code. For example, F# produces intermediary language code, with a close correspondence to the source text, and with sensible generated identifier names. This means debuggers, profilers and other tools not only work without any problems, but also that their results are just as intelligible as when applied to C# code. Furthermore, F#’s excellent bi-directional language interoperability means that you can even use code generation tools such as parser-generators.

Because of this, F# has a surprisingly powerful and complete set of tools for a research language. Traditionally, functional languages have not had good profilers or graphical debuggers. With F# these tools essentially come for free.

The most important tools supported by F# are:

  • A command line compiler (fsc.exe) supporting separate compilation.
  • Graphical interactive debugging (via Visual Studio).
  • Parsing and Lexing (fslex.exe and fsyacc.exe).

Debugging

Debugging with Visual Studio.NET is well supported. Debugging is supported through any .NET debugger, e.g. the command line “cordbg” tool that comes with the .NET Framework SDK, or the graphical debugger “DbgClr”.

Jun 26

F# for Visual Studio

F# for Visual Studio provides several features which greatly help writing F# code, both in general and specifically when using the .NET APIs.

  • Codesense. Within Visual Studio, F# will typecheck your file as you type.
  • TypeTips. Hovering over identifiers will report their type. Languages with automatic type inference are fantastic for authoring code. This extension to VS allows readers of the code to see the types without needing to work them out.
  • Intelisense. This allows for discovering possible completions based on type and context. It is activated when you press a “.” (dot) after an object name or directly via CTRL-J. This enables rapid discovery of APIs.
  • MethodTips. F# for Visual Studio displays the calling signatures for methods as they are selected. This information is available for both F# values and .NET members.
  • PatternTips. F# for Visual Studio displays the …

See the F# intellisense screenshots from Don’s F# Blog.

So, for example, if you have the following code:

    let gc = System.Drawing.Graphics.FromImage(im)
    do gc.Draw

typing CTRL-J after gc.Draw will give a menu of possible Draw* methods on gc and hovering over gc reports it’s type as Graphics.

F# for Visual Studio Installation

To install F# for Visual Studio, see the instructions in your release’s “README-fsharp.html” file.

F# project properties

You can refer to additional .dlls in your project by adding:

    -r extra.dll

to the command line options under the F# project properties. Note, the F# Intelisense process is given these options when it is started, so restart Visual Studio to make Intelisense detect dll reference changes.

Jun 26

F# Hello Winform

The following is a hello world WinForms example:

    open System
    open System.Windows.Forms

    let form = new Form()
    do form.Width  
              

If you save the above as

    devsrchelloforms.fs

then assuming fsc is in your path, you can compile and run it as follows:

    cd devsrc
    fsc devsrchelloforms.fs
    helloforms.exe