In this post we would talk about REPL which is the provided by the F# interactive enviorment. It could be used as tool window inside Visual studio or as stand alone command line application. Its really useful as we can evaluate the Code within the Visual Studio enviorment easily. It can used during or before editing the code in the editor. Lets see how this works.
- Create a new F# application and add the following code to it.
- The use of the interactive enviorment is pretty easy. Just right click on the first line of code and select – Send to Interactive.
- It will automatically bring up the interactive window within the F# enviorment and evalute the selected line of code.
- We can also type in the interactive window for evaluatig the code, but once we type the code to evaluate and hit enter the evaluation will not start so we need to terminate the code line with two semi colons and press enter. As F# does not have its own line termination but in the intercation window we need to treminate the statement with two semi colons. Once you press enter you would see the statement is evaluated and the interactive tool tells you the variable delared is an integer with value as 100.
- Now you can evaluate almost any F# code using the Interactive evaluation there and some restriction on the automatic evaluation. Now if you evalute a System.Console.ReadLine, it would work perfectly fine but if you select all the code written above in the Program.fs and send it to interactive the Console.ReadLine would retrieve an empty string. So we need to to careful at some places withis tool.
- The compile langauages before F# did not had this capability so its really nice to have this stuff but you need to be careful while using it.
Any feedback, comments and questions are requeted.