Suppress "val it" output in standard ML

I write a "script" in standard ML (SML / NJ), which customizes the interactive environment to your liking. The last thing the script does is print a message stating that everything went smoothly. Essentially, the last line is this:

print "SML is ready.\n"; 

When I run the script, everything goes fine, but the SML interpreter displays the return value from the print function.

 SML is ready. val it = () : unit - 

Since I'm just printing something on the screen, how can I suppress the output of "val it = (): unit", so all I see is the message "SML is ready", followed by an interpreter prompt?

+7
sml smlnj
source share
2 answers

To cancel the SML-NJ request and response, use the following assignment.

 Compiler.Control.Print.out := {say=fn _=>(), flush=fn()=>()}; print "I don't show my type"; I don't show my type 

although I don’t understand why the print function returning a type is bad.

The say function determines what is printed.

The following SML / NJ notes have a larger example http://www.cs.cornell.edu/riccardo/prog-smlnj/notes-011001.pdf

UseSilently function can be used to download a file, but without displaying any output related to downloading

 fun useSilently (s) = let val saved = !Compiler.Control.Print.out fun done () = Compiler.Control.Print.out := saved in Compiler.Control.Print.out := {say = fn _ => (), flush = fn () => ()} (use (s); done ()) handle _ => done () end 

This essentially changes the say function to do nothing, and then install it at the end.

+10
source share

Use this:

 val _ = print "I don't show my type"; 
+2
source share

All Articles