5 Reasons to use F# Interactive in Visual Studio 2010

Note: While the following post is targeted at Visual Studio 2010 users, most of the points apply even if you aren’t using Visual Studio 2010. F# Interactive (FSI) is easy (and free) to install for Visual Studio 2008 users and command line users running in Windows or Mono. Details are available at the F# Developer Center.

1) You already have it

F# comes standard with Visual Studio 2010, and it includes F# Interactive. There’s nothing to install, and no configuration is required. You don’t even need to start a F# project in order to use FSI. From anywhere inside Visual Studio, select View | F# Interactive, or just press Ctrl + Alt + F to bring up an FSI instance.

2) Performance Analysis

With the #time option enabled, F# Interactive is a surprisingly useful tool for performance analysis. A few days ago, coworkers Jay Wren and Ben Barefield asked me to help determine why a LINQ statement they wrote was running slowly. After spending time looking over the code and running it through a profiler, we wanted to see how LINQ’s distinct statement behaved with different inputs. Within a couple minutes, I was able to get information using F# Interactive.

F# Interactive is no substitute for more sophisticated performance analysis techniques, but when it comes to getting fast answers to test bottlenecks, it’s a great tool to have at your disposable.

3) Verifying the Behavior of Base Class Library Functions

There are a lot of APIs in the Base Class Library, and it can be tough to remember exactly how everything works. Let’s say you can’t remember if the Insert function on List<T> inserts elements before or after the input index. You could write a small console application or a throwaway test to verify the behavior, but it’s a lot faster to use FSI:

4) Learning F# and Functional Programming

Learning any language teaches you new coding techniques. Learning a functional language teaches you new problem solving techniques. F# Interactive lets you do both without leaving Visual Studio or closing your open project. Whenever you have a few minutes to kill during development, you can easily open a FSI window and play around with F#. You can also use it to deep dive and explore syntax and techniques with a more extended session. Finally, using F# Interactive while programming in another .NET language is a great way to keep your F# skills sharp even if you aren’t writing F# on a daily basis.

5) Spikes and Scripting

This is probably the first use case that people think of when they see FSI (or other REPLs). In practice, I find that I use F# Interactive more for performance analysis, learning F#, and verifying Base Class Library behavior than for spiking or scripting. However, it’s worth pointing out that F# Interactive is a powerful tool for quickly exploring problem domains. By creating script files, you can build up situations to evaluate different approaches without investing a lot of time setting up a dummy project or a clumsy test harness.

[…] I could get my feet wet with, I realized the possibilities for automating VisualStudio by using F# Interactive (a F# console that can also be used inside Visual Studio – the other way would be to call fsi […]