A constructor{A} T
for some abilityA
and some typeT
(or a function which uses such a constructor), can only be used in a scope where the abilityA
is provided. Abilities are provided byhandle
expressions:
handle e with h
This expression givese
access to abilities handled by the functionh
.Specifically, ife
has type{A} T
andh
has typeRequest A T -> R
,thenhandle e with h
has typeR
.The type constructorRequest
is a special builtin provided by Unison which will pass arguments of typeRequest A T
to a handler for the abilityA
.Note thath
mustaccept an argument of typeRequest A T
to handlee
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.