fsharpc == command line compiler
fsharpi == command line interactive (REPL)
For .NET:
fsc.exe == command line compiler
fsi.exe == command line interactive (REPL)
So I'll start by messing around with the interpreter. A REPL is a hugely beneficial tool when learning a language or trying out code you don't understand. It won't take me too far, because doing anything complicated requires more flexibility, but it's a great way to test understanding.
I'm also going to use the tutorials over at Try F#. You can do the same if you like. Okay, I'm ready to learn some basics!
Matthews-MacBook-Pro:~ Matthew$ fsharpi
The REPL tells me I can get help with the command #help;; so I'll try that first. Here are a few fundamentals of the REPL:
- Every statement or block needs to be followed with ;;. This tells the REPL to process the command. This doesn't seem to be part of the language, just a convention of the interactive F#.
- The REPL responds to commands that start with a hash mark. It took me a minute to figure this out, because I didn't use #help;;. Be smarter than me and use the help menu!
- #help;; Access the help menu.
- #quit;; Quit the REPL.
- #r "File.dll";;
- Assuming that the "r" stands for reference; allows you to reference a dll. I'll take that for a spin.
- #I "path";;
- Looks like you can add a path to include dlls.
- #load "file.fs" ...;;
- If I want to load a script and then play around with it in the REPL, this command should do that for me.
- #time ["on"|"off"];;
- No idea. Maybe this gives you stopwatch data about the executing code?
I'm curious about that #time;; option so I'll try that first.
> #time "on";;
--> Timing now on
> let me = "spotaneous";;
Real: 00:00:00.000, CPU: 00:00:00.003, GC gen0: 0, gen1: 0
val me : string = "spotaneous"
That's pretty cool! So I can do some primitive optimization in the REPL by comparing the timing of different code options. It's not something I need right away, but cool nonetheless.
It's worth noting that this is how the REPL reports the value of a reference:
val me : string = "spotaneous"
It looks a little confusing to me, since it looks suspiciously like a variable assignment in another language, but it's not. I can check the value referenced by:
> me;;
Real: 00:00:00.000, CPU: 00:00:00.000, GC gen0: 0, gen1: 0
val it : string = "spotaneous"
No comments:
Post a Comment