Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does val it = () : unit mean in SML?

Tags:

sml

smlnj

I've never programmed in SML before, and I'm using SML/NJ. It keeps giving me the following at the end of each program I run:

val it = () : unit

What does this mean? Is it something I'm doing wrong?

like image 822
Horse SMith Avatar asked Oct 22 '13 22:10

Horse SMith


2 Answers

it is the name of the result returned by your code. () : unit is a trivial placeholder value returned from things that are side-effect based.

It's more obvious when you enter something that's more commonly an expression at the prompt, e.g...

- 2 * 7;
  val it = 14 : int
like image 163
Amber Avatar answered Jan 02 '23 11:01

Amber


You can also use it for the side effect of printing things out:

fun printpos n = 
    if n <= 0 then (print "not positive!\n") 
    else (print (Int.toString n); print "\n");

 printpos ~1;
 printpos 1;

(* Output:
val printpos = fn : int -> unit
not positive!
val it = () : unit
1
val it = () : unit
*)
like image 20
Chuck Allison Avatar answered Jan 02 '23 12:01

Chuck Allison