问题
I'm trying to write command line scripts, but SML's warnings obfuscate the interface.
The docs say to use:
Compiler.Control.printWarnings := false;
But SMLNJ has since renamed these to:
Control.printWarnings := false;
Which actually produces even more printouts.
Example:
$ cat hello.sml
print "Hello World!\n";
OS.Process.exit(OS.Process.success);
$ sml hello.sml
Standard ML of New Jersey v110.72 [built: Mon Nov 14 17:30:10 2011]
[opening hello.sml]
Hello World!
val it = () : unit
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
hello.sml:2.1-2.36 Warning: type vars not generalized because of
value restriction are instantiated to dummy types (X1,X2,...)
Versus:
$ cat hello.sml
Control.printWarnings := false;
print "Hello World!\n";
OS.Process.exit(OS.Process.success);
$ sml hello.sml
Standard ML of New Jersey v110.72 [built: Mon Nov 14 17:30:10 2011]
[opening hello.sml]
[autoloading]
[library $smlnj/compiler/current.cm is stable]
[library $smlnj/compiler/x86.cm is stable]
[library $smlnj/viscomp/core.cm is stable]
[library $smlnj/viscomp/basics.cm is stable]
[library $smlnj/viscomp/elabdata.cm is stable]
[library $smlnj/viscomp/elaborate.cm is stable]
[library $SMLNJ-BASIS/basis.cm is stable]
[library $smlnj/viscomp/debugprof.cm is stable]
[library $SMLNJ-LIB/Util/smlnj-lib.cm is stable]
[library $smlnj/MLRISC/Control.cm is stable]
[library $SMLNJ-MLRISC/Control.cm is stable]
[library $controls-lib.cm(=$SMLNJ-LIB/Controls)/controls-lib.cm is stable]
[library $smlnj/smlnj-lib/controls-lib.cm is stable]
[autoloading done]
val it = () : unit
Hello World!
val it = () : unit
[autoloading]
[autoloading done]
回答1:
First of all you would want to fix those warnings, instead of just ignoring them. Anything else is just ugly habit!
print "Hello World!\n";
val _ = OS.Process.exit(OS.Process.success);
Besides that, as far as I know: There is no way of getting rid of the autoloading messages in sml/nj. You could try another interpreter. Poly/ml doesn't say much, however I can't seem to find a way to start it on a file. Mosml doesn't chat much either, and here you can start it on a file (even an .mlb file as far as I have been told -- it is undocumented).
Another way would be to compile your files, however then the purpose of scripting kind of fades away.
You have stumpled upon one of the cases where sml aren't the right tool for the job.
Update.
I found out that you can actually get some of the way by setting verbose to off in the compilation manager's controller:
;#set CM.Control.verbose false;
This gets rid of most, however it still prints some auto loading messages, as it has to load the CM.Control structure. And it only shuts up afterwards. The documentation however also suggests that you can set the environment variable CM_VERBOSE
CM_VERBOSE=false sml foo.sml
which makes it almost quiet. Using this source
val _ = print "Hello World!\n";
val _ = OS.Process.exit(OS.Process.success);
generates the following output:
$ CM_VERBOSE=false sml foo.sml
Standard ML of New Jersey v110.72 built: Wed May 12 15:29:00 2010]
[opening foo.sml]
Hello World!
Note the val _ = ...
to not have it write val it = () : unit
each time.
来源:https://stackoverflow.com/questions/8186848/how-to-disable-smlnj-warnings