Welcome to the F# CTP project system: project templates
Posted by Brian on August 29, 2008
As you may have already heard, the F# CTP has been released! Here is the release announcement. I’ll continue describing the F# project system, but now that the CTP is out, you can follow along on your own machine, rather than just having to soak in the teaser screenshots I posted in prior blog entries. :)
Today’s blog entry describes the F# project templates. Whereas the prior releases of F# came with only one project template, the CTP release has three. Inside Visual Studio, do a "File>New>Project" and select the "Visual F#" node to see this:
(Aside: if you’re like me, and you still have a prior install of F# on your machine, the old project template will still appear in "Other Project Types > F# Projects" under "Project types". So if you’re only seeing the old template after installing the CTP, make sure that you have selected the new "Visual F#" node and not the old "F# Projects" node:
Also, note that my screenshots today are from my computer at home, which has only the free Visual Studio 2008 Shell installed. If you have a full version of Visual Studio, then you’ll also see other project types, such as "Visual C#", in the "New Project" dialog.)
There are three types of F# project templates in the F# CTP release; I’ll describe each in turn.
The "F# Application" template is used to build an executable program (EXE). It will start you with a single source code file, Program.fs. Type in some code, and you can just build and run:
The "F# Library" template is used to build a library (DLL), which you might later reference from another application (and that application might be written in F#, or C#, or whatever – see my previous blog entry on project references). The "F# Library" template starts you off with two files: Module1.fs, an F# source code file that will be compiled into the library DLL, and Script.fsx, an F# script file which is not compiled into the library DLL. I’ll talk more about F# script files in a future blog entry; briefly, scripts are one easy way to associate extra functionality (such as unit tests) with a particular project, without that functionality being compiled into the project.
The "F# Tutorial" template’s main purpose is to demonstrate some of the main features and syntax of the F# language with some sample code. If you are relatively new to the language, reading the code in Tutorial.fs is one way to get a quick introduction to F#. It’s also useful if you need a quick refresher to remember the syntax for a particular feature. For instance, if I forget how to author a class that implements an interface, I can scroll down through the tutorial code and find:
There’s lots more to talk about with the new project system… more blog entries coming soon! (If you have questions in the meantime, feel free to post them in comments on this blog, or to use the forums on the hub.)