Printing and the clock (IO)

Partly built

IO.print and IO.now: what a program can do to the outside world, and what Run shows.

A program can print a line and read the clock. Both need the built-in IO ability, which you do not declare (Unison’s own {IO}); a function that uses either must say so in its <...> list, exactly like any ability.

let main<IO> = (): unit => {
let a = IO.print("hello")
IO.print("world")
}

let stamp<IO> = (): int => IO.now()
  • IO.print(text) writes the text and a newline, and gives back unit.
  • IO.now() returns microseconds since the epoch as an int. It takes no arguments.

Leaving <IO> off is a type error, not a runtime surprise.

Running it

Press Run: printed lines appear under the definition’s name, then the result. It runs in your page first (so it works offline), then, if the server is reachable, again through Unison, and the two are compared. IO.now() results are shown but not compared, since two runs cannot agree on the time.

Not there yet

  • A bare expression on its own line works (IO.print("a") then the next line); it is the same as let _ = ... and hashes identically. Names of the form _stmt0 are reserved for it.
  • No IO.eprint, reading input, files or network.
  • clay eval does not show printed output yet.
  • Run only executes in the page when everything it needs is in the open file; otherwise the server runs it.