4

I'm on linux and I'd like to use an interactive command line repl for F#.

For example, like the node repl.

What options are there?

Mateja Petrovic
  • 3,799
  • 4
  • 25
  • 40

3 Answers3

5

Rather than typing directly into a REPL, I recommend creating an F# script file (.fsx) in an editor with F# support, e.g. Visual Studio Code. Then you can type script code with the usual benefits type-checking and auto-completions, and just select sections of code and send them to FSI (F# Interactive), usually by pressing Alt-Enter.

TheQuickBrownFox
  • 10,544
  • 1
  • 22
  • 35
3

TheQuickBrownFox has a good suggestion, but sometimes I find it's easier to type a quick bit of test code into an actual REPL rather than editing an .fsx file in VS Code. The F# REPL is available with the fsharpi command. It's part of the fsharp package (at least on Debian-based systems) so you should already have it installed.

rmunn
  • 34,942
  • 10
  • 74
  • 105
  • And if not, a simple `sudo apt-get install fsharp` should do it. – Aaron M. Eshbach Sep 14 '18 at 19:23
  • That's it, thanks a lot rmunn. Although I did find it weird that every line needs to end with a double semi-colon, ie. printf "Hello World";; – Mateja Petrovic Sep 14 '18 at 20:40
  • 1
    The double-semicolon is [an artifact of F#'s history](https://stackoverflow.com/questions/2669299/when-do-you-put-double-semicolons-in-f), specifically its early attempts at being compatible with OCaml. More details at the link. – rmunn Sep 14 '18 at 21:07
  • I'm guessing the fsharp package has been superseded by the F# SDK (see Chris K answer) – David Savage Feb 06 '23 at 09:06
2

Under openSUSE Leap 15.3 the command is dotnet fsi. (Having followed these F# SDK installation instructions.)

Chris K
  • 1,376
  • 1
  • 14
  • 18