Ability handlers

A constructor {A} T for some ability A and some type T (or a function which uses such a constructor), can only be used in a scope where the ability A is provided. Abilities are provided by handle expressions:

handle e with h

This expression gives e access to abilities handled by the function h. Specifically, if e has type {A} T and h has type Request A T -> R, then handle e with h has type R. The type constructor Request is a special builtin provided by Unison which will pass arguments of type Request A T to a handler for the ability A. Note that h must accept an argument of type Request A T to handle e of type {A} T - ultimately, a type error will result if an ability is required in a scope where it is not provided by an enclosing handle expression.

The examples in the next section should help clarify how ability handlers work.