This program is exactly what we usually recommend for people who aren't using SML/NJ inside of an Emacs inferior window (which is far and away the most common usage mode for experienced SML/NJ programmers - all ten of us <grin>).
I personally apologize for my laziness. Two or three different times I've started in on making something similar to the haskeline package in GHC to provide readline-style support to make life easier for students, but have never quite finished it up. Unfortunately, "just linking" readline/libedit isn't a very friendly solution given the way that the interpreter is currently architected, as it's written on top of the ML basis library primitives for reading/writing individual characters from the input stream.
Thanks for mentioning Emacs: You made me realize why this hadn't come up in the course notes or material for the Coursera class I'm doing[1]: they explicitly recomment using SML inside Emacs. Unfortunately, I'm a relatively long-time Vim user, and I'm just not comfortable editing in Emacs. So I came to this round-about solution.
Thank you also for the mention of Emacs. After six years of using Emacs with a lisp REPL, where I could scroll back through function definitions and edit them in place, I feel distinct frustration every single time I use a Python REPL. One-line-at-a-time scrollback is absolutely frustrating.
I personally apologize for my laziness. Two or three different times I've started in on making something similar to the haskeline package in GHC to provide readline-style support to make life easier for students, but have never quite finished it up. Unfortunately, "just linking" readline/libedit isn't a very friendly solution given the way that the interpreter is currently architected, as it's written on top of the ML basis library primitives for reading/writing individual characters from the input stream.