A Taste of F# Interactive in Visual Studio







Here’s a taste of some great new functionality that will be in the next release of F#, which we should have out sometime in the next week or so. The cool thing here is not just the pretty graphics (which you’ve been able to do in F# for a while now), but F# Interactive (fsi.exe) embedded as a tool window in Visual Studio. Click on the screen shot for an enlargement.


 


Also shown is something I haven’t made much noise about on this blog, and that’s the ability to display windows interactively from F# Interactive.  The windows are fully active – they can paint and respond to interactions while the programmer evaluates new expressions, code, types and classes in the interactive session.  You can also dynamically load new .NET components on-the-fly.


At the bottom of the screen you’ll see a tool window containing the F# Interactive session. The WinForms/DirectX window in the foreground was created by running simple F# code such as


let form = new Form();;
form.Text <- “F# surface plot”;;


as well as some introductory DirectX triangle creation. 


The code shown in the editor is part of this script – we’ve just executed the command that specifies a new function to display (this is the line highlighted in the editor).  We did this just by evaluating the code in the F# Interactive Session below using a key short-cut.  (I’ve scrolled the F# Interactive window back up to the top so you can see the banner printed out when F# Interactive starts up.)


What’s really striking is the combination of interactive visualization, Visual Studio, .NET programming and efficiently executing F# code (remember, .the floating point code is running as optimized native code, often close to C++ speed).  We have a few things to add before this is complete: for example some form of intellisense in the interaction window.  But this combination feels like it is bringing many things together nicely.  (Aside: you can of course do interactive visualization when using F# Interactive from Emacs too 🙂  I’m not so sure about “vi” !!)

Comments (32)

  1. lbruck says:

    This is going to be so cool 🙂

    Can you give a hint of what level of communication is available between the fsi window and the code windows?  If I make a change to a file that has been "#use"-d in fsi, can I have it automatically loaded once it compiles OK?

  2. NA says:

    Please add FSI following features !

    . one key stroke history(most important)

    . GUI reference selector(I can’t understand why my project’s dll is rejected by FSI)

    . saving functionality for saving usually using dll

  3. sp says:

    Is this functionality in the release version 1.1.10.4?

    I have installed it, but cannot find mention of the tool in the documentation or the VS2005 menus.

  4. dsyme says:

    Hi sp,

    Yes, this is in 1.1.10 and 1.1.11 – look for "Using F# Interactive in Visual Studio", and also look under the AddIn Manager

    Don

  5. Dave Cooper says:

    From the F# Site at http://research.microsoft.com/fsharp/fsharp.aspx

    F# is a programming language that…

  6. Himuro says:

    F# on VS2005 is great, but I cannot use F# interactive on VisualStudio2005 Version 8.0.50727.42(Japanese).

    When I invoke F# interactive Add-in, below dialog  is showed 2 times.



    Raised: System.ArgumentException: value is out of range

    at EnvDTE.Command.set_Bindings(Object pVar)

    at Microsoft.FSharp.Compiler.VSFSI.Locals.addCommand@25.Invoke(Unit _unit)

    Microsoft.FSharp.Compiler.VSFSI.Locals.catchAll(FastFunc `2 f)



    F# interactive window is correctly showed, but "Alt-Enter" doesn’t work.

    I hope this is bugfixed.

    Thanks.

  7. Stephen says:

    Oh my goodness! I just tested it and it works. F# is such a delightful treasure trove. I’m starting to notice the wrinkles in our good old C#.

  8. Microsoft F# September 2008 CTP

  9. Don Syme has announced that F# would ship as part of Visual Studio 2010 in his blog entry, F# to ship

  10. Randy says:

    I think that this maybe what all the hype about EMACS.NET was about.

  11. Danny S says:

    It is a shame that the image here is no longer there. F# sounds very interesting – I may have to find a little time to play with it.