Search code examples
datetimesmlsmlnj

How to get the current time?


I looked at the TIME signature for Standard ML and tried the following:

- Time.now;
val it = fn : unit -> Time.time

So it gives me back a function - how do I get the current time in Standard ML?


Solution

  • It doesn't give you back a function, it is a function.
    Try some other functions and the output is very similar:

    - List.hd;
    val it = fn : 'a list -> 'a
    - String.str;
    val it = fn : char -> string
    

    Time.now is a function from unit to Time.time.
    The only value of the type unit is written () (which is also called "unit"), so you call it like this:

    - Time.now ();
    val it = TIME {usec=1516525299967615} : Time.time