Effects

Name outside work.

An effect names work that asks the outside world, runtime, or host for an answer.

let Clock := effect {
  let tick () : Int;
};

ask Clock.tick();

Define an effect

let Clock := effect {
  let tick () : Int;
};

The effect says what can be asked. It does not decide who answers.

Ask for an effect

ask Clock.tick();

ask marks the boundary clearly. A reader can see that the expression needs an effect provider.

Keep pure code separate

Pure functions should take values and return values. Effectful code should live near the boundary where answers are provided.

Effect operation shape

An operation inside an effect looks like a function signature.

let Clock := effect {
  let tick () : Int;
};

tick takes no arguments and returns an Int. The effect declaration does not say where the value comes from.

Ask site

ask Clock.tick();

The ask site is where the program requests that value.