Tuesday, January 19, 2016

The Book of F#, Chapter 2: F# interactive

This one’s going to be brief!

Chapter 2 covers how to use F# Interactive, which is a nice REPL (read–eval–print loop) shell that can run inside Visual Studio, or on its own.

It’s fairly simple: you type the code you want to execute, terminating each statement with ;; to execute it. As well as outputting the return value of your statement (which will be bound to the name it if you don’t specify a binding, it also prints that data type of the value. I suspect this will be useful when prototyping code, playing around with expressions in a shell to try and get the right data structure sounds a lot easier than trying to manipulate the source file!

There are also a bunch of directives that enrichen the tool, and allow you to do things like load the code from file with #load or load an entire assembly with #r.

Finally, rather than standard F# source files (with the .fs extension), you can also create script files (.fsx) which can be executed directly by F# interactive.

So overall it’s a nice thing to have, but nothing to write home about.

Next time, we’ll get into the meat of the F# syntax when we explore the fundamentals of the language.

No comments:

Post a Comment