Inside F#

Brian's thoughts on F# and .NET

Another release of F# along with VS2010 Beta2

Posted by Brian on October 19, 2009

If you’ve been anxiously awaiting another release of F#, then today is your day!  Check out Don’s blog for the release announcement as well as the release notes.  As usual, you can either download the CTP to run atop your VS2008 (or VS Shell), or install the VS2010 Beta.

That’s the big news… to avoid a one-paragraph blog entry for today, I thought I’d take a moment to point out a few new small features that are not mentioned in the release notes.

Error messages have unique numbers

If you are very observant, you may have noticed that prior releases of the F# compiler used the error code “FS0191” for a wide variety of error messages (perhaps 1000 different circumstances!).  For example:

type Foo() =
    private member this.F() = ()    

would yield

...\Program.fs(2,5): error FS0191: Visibility declarations should come immediately prior to the identifier naming a construct

in the prior release.  But now you get

...\Program.fs(2,5): error FS0531: Accessibility modifiers should come immediately prior to the identifier naming a construct

Not a huge difference, but moving forward, if you are looking for more information about an error message, it should be much easier to Bing for e.g. “FS0531” and find the exact information you’re looking for (rather than sifting through lots of info about unrelated errors).

Some common error diagnostics have been improved

Using the prior release, this (contrived) code snippet

let f x = 42
let r : unit = f 0
f 0

would yield these two diagnostics:

...\Program.fs(2,16): error FS0001: This expression has type  int but is here used with type  unit
...\Program.fs(3,1): warning FS0020: This expression should have type 'unit', but has type 'int'.

I must confess, it always irked me that these two similar messages had the ‘expected’ versus ‘actual’ types presented in opposite orders.  With the new release, you get:

...\Program.fs(2,16): error FS0001: This expression was expected to have type     unit     but here has type     int
...\Program.fs(3,1): warning FS0020: This expression should have type 'unit', but has type 'int'. 
Use 'ignore' to discard the result of the expression, or 'let' to bind the result to a name.

Now these two diagnostics are parallel, and furthermore FS0020 now reminds you that you want to either pipe the result to ignore (e.g. if just calling a function for its side-effects) or else use the result.  There are a handful of minor diagnostic improvements like this (though there is still plenty of room for us to continue to improve).

VS2010 Beta2 has more item templates

In the prior release, ‘Add New Item’ on an F# project only had three default item templates:

 Beta1ItemTemplates

In the VS2010 Beta2 release (but not in the CTP) there are three more – templates for “xml file”, “text file”, and “app.config” are in the list by default.  (Sorry, I have no screenshot handy.)  Note that regardless of what templates you have, you can always ‘Add Existing Item’ on some file to add it to the project, and VS is smart about picking an appropriate editor for that file type.  For example, drop an HTML file in the directory of an F# project, ‘Add Existing Item’ of that file, double-click the solution explorer icon for the new file, and the file is opened in the HTML editor.

More to come!

I have more topics I intend to blog about regarding the latest release of F#, and hope to do so soon.  In the meantime, go download the latest version (installing only after uninstalling the previous one), and as always, send us feedback or bug reports!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: