REPL Development using F# Interactive in Visual Studio Code

Now that we have Ionide installed, we can do REPL development by using the F# Interactive console (FSI).

There are a couple of ways of getting FSI to run your code:

  1. Sending the selected code to FSI.
  2. Sending the current line to FSI.
  3. Sending the whole file to FSI.

For the first two options, you don’t need to be working in an existing F# file. You can just create a new tab, start typing, select the code and send to FSI.

Caveat: I found that if you wanted Intellisense to work you needed to be working in a saved .fsx or .fs file (see reported issue). You can’t just change the language mode to F#.

Start FSI

To get started with FSI, you need to start it. To do so, open the Command Palette (⇧⌘P) and typing in “FSI: Start”.

The output panel will display like so:

Run code in FSI

Type in some F#. Then select the F# code you want to run and then select “FSI: Send Selection” from the Command Palette or type in ⌥Enter. This will take the code you have selected and run it in FSI and give you the result in the Output panel.

If you made a mistake in your F# code, you’ll see the compiler or runtime output in the Output panel. E.g.:

You can also send the whole file to FSI, however for that you need to be working in an existing file. Once you are working in an F# file, you can send the whole file (including your current unsaved changes) by selecting “FSI: Send File” from the Command Palette. However I found it easier to just select the content of the file (⌘A) and then send the selection to FSI.