Executing F# scripts

As there are no answers so far, I'll try to turn my earlier comment into an answer with some more details.

I just tried to create a standard windows association for *.fsx files to open them automatically in fsi.exe and it works with no problems - when you open the fsx file, it runs F# Interactive and automatically evaluates the content of the file. This corresponds to running the command:

> fsi.exe test.fsx

However, I think that it is much easier to learn F# by using F# Interactive from Visual Studio. Even if you don't have a licence, you can use Visual Studio Shell with the free F# plugin. I think SharpDevelop also provides similar integration (but probably not with some limitations).

The easiest way to start is to create a new "F# Script" (File -> New -> File...) and then start writing some code (in an assorted order). Then you can select some part of the code and evaluate it in the F# Interactive window by perssing [Alt] + [Enter]. You'll first need to open the F# Interactive window, which can be done using [Ctrl] + [Alt] + [F] or you can find it in the View -> Other Windows menu item.

I think most of the F# webcasts use F# Interactive in this way, so if you look at some of them, you should get a good idea how to use it. Look for example at How Do I? videos at www.fsharp.net or F# videos at Channel 9.


Yes it is possible.

There are two keys here:

  1. You need to bind an application to execute to the ".fsx" extension. The exact way to do this may vary a bit between operating system versions (I have only done this in the past by editing the registry directly, so I can't provide a generic solution here); make sure the command to be executed does include the script arguments (as %*), so the shell\open\command entry in the registry for the binding should look like

    "c:\Program Files\FSharp-1.9.9.9\bin\fsi.exe" "@%1" %*

    See Gradbot's response for more details.

  2. You may want to add the extension you want to trigger script execution (".fsx" in this case) to the PATHEXT environment variable, so CMD.exe can find the script even without you specifying the script's extension. A warning: if you are concerned about your system's security, reconsider this step - the fact that VBScripts are registered on a default Windows XP and older systems to provide a similar feature has been exploited in the past by virus writers (I don't know if this is still true on Vista or windows 7).

Tags:

.Net

F#