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:
- Sending the selected code to FSI.
- Sending the current line to FSI.
- 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#.
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.