0

I am new to SML, but would like to get some experience with a strongly typed language. I've been looking at tutorials and I copied a simple factorial function:

fun Factorial n =
    if n = 0 then 1
    else n * Factorial (n-1);

However, I am not sure how to save this program (Factorial.sml) in order to run it later. Also, I am confused as to how I pass an argument to this function; how would I run this function with n=5?

tpm900
  • 271
  • 5
  • 11
  • It is possible to compile programs to stand-alone executables with SML/NJ. But -- it isn't easy. For learning the language -- just use the REPL for experimenting with function definitions. Save code in simple text files with a `.sml` extension (if you are on a Windows machine -- the editor `Textpad is fairly nice: https://www.textpad.com/ . You can download an SML syntax definition file for syntax highlighting). Then, in the REPL, type `use "path/filename.sml";` to load the definitions in the file into the REPL. – John Coleman Jan 22 '17 at 18:26
  • Thanks! That is what I will do – tpm900 Jan 22 '17 at 18:52
  • @JohnColeman: You should put that comment in an actual answer. :) – sshine Jan 23 '17 at 08:44

0 Answers0