Ship

Lexicon · Service

Service

One kind of effect: an external capability (Postgres, HTTP, filesystem, email, queues, …) tracked in a function's effect row. The lifecycle-managed, tail-resumptive specialization of an effect (see ../10-services.md). Ambient defaults: Clock, Console, Random, Logger, Config, Runtime.

Declare effect interfaces with effect service Name { ... } (sibling kinds: effect control, effect command). Members bind names to function types with : — same field rule as product types:

effect service Logger {
  info: pure fn!(msg: String) -> Unit;
  error: pure fn!('error)(msg: String, cause: Cause('error)) -> Unit;
}

Declare concrete providers with let service Provider: Name = .... Providers must declare type t, init, drop, and implementations whose first parameter is self: t:

let service JsonLogger: Logger = {
  type t = { out: Stream; };
  init = fn() -> t { ... };
  drop = fn(self: t) -> Unit { ... };
  info = fn(self: t, msg: String) -> Unit { ... };
  error = fn('error)(self: t, msg: String, cause: Cause('error)) -> Unit { ... };
};

Ordinary calls such as Logger.info("started") infer eff Logger; users do not write routine use Logger statements.

See services and effects.