Package basic

Built-in package

Modules

Console

Terminal input and output.

let console = Console.Open
console.print("Hello from Par!")
console.close
type Console = iterative choice {
  .close => !,
  .print => [String] self,
  .prompt => [String] (Option<String>) self,
}

An interactive terminal handle.

  • .close — close the console.
  • .print(s) — print a string followed by a newline.
  • .prompt(s) — print a prompt string (no newline), read a line from stdin. Returns .ok with the input (trailing newline stripped), or .err! on EOF.
let console = Console.Open
console.print("Hello!")
console.prompt("Name: ")[name]
name.case {
  .ok name => console.print(name),
  .err! => {},
}
console.close
dec Console.Open : Console

Opens a new Console connected to stdin/stdout.

Http

HTTP request and response types, plus client and server operations.

Request and response bodies are Bytes.Reader<Error> values, so body data can be consumed incrementally.

type Http.Error = String

Error type for HTTP operations (a human-readable message).

Sends an HTTP request and returns the response.

let try url = Url.FromString("https://example.com")
let try (status, headers) body = Http.Fetch(
  ("GET")
  (url)
  (*())
  Bytes.EmptyReader
)
dec Http.Listen : [String] recursive either {
  .incoming (Http.Request, [Http.Response] Result<Http.Error, !>) self,
  .shutdown Result<Http.Error, !>,
}

Http.Listen(address) starts an HTTP server on address, such as "127.0.0.1:8080".

Returns a recursive stream of events:

  • .shutdown result — the server has shut down (e.g. on Ctrl+C or error).
  • .incoming(request, respond) next — a request arrived. Call respond with a Response to send the reply. The result indicates if sending succeeded.
Http.Listen("127.0.0.1:8080").begin.case {
  .shutdown try! => ...,
  .incoming(request, respond) next => {
    let (method, url, headers) body = request
    body.close
    respond((200, *()) Bytes.EmptyReader)
    next.loop
  }
}
Os

Operating system interfaces for paths, files, directories, standard streams, and environment variables.

Most operations return Result<Os.Error, ...>.

type Os.Error = String

Error type for OS operations (a human-readable message).

type Os.Path = iterative@append recursive@parent box choice {
  .absolute => Bytes,
  .append => [Bytes] self@append,
  .name => Bytes,
  .parent => Option<self@parent>,
  .parts => List<Bytes>,
}

A filesystem path value.

  • .name — get the file name component as bytes.
  • .absolute — get the absolute path as bytes.
  • .parts — get all path components as a list of byte sequences.
  • .parent — get the parent path, or .err! if at root.
  • .append(part) — return a path with one more path component.
dec Os.TraverseDir : [Os.Path] Result<Os.Error, recursive either {
  .dir (Os.Path, self) self,
  .end !,
  .file (Os.Path) self,
}>

Recursively traverses a directory tree, returning a nested structure of files and subdirectories sorted by name.

  • .end! — no more entries.
  • .file(path) rest — a file, followed by more entries.
  • .dir(path, children) rest — a subdirectory with its nested contents, followed by more entries.
Time
dec Time.Now : [!] Nat

Returns the current time as milliseconds since the Unix epoch.