Normally, exiting from an abstraction is done simply by ``falling off'' (one of) the tip(s) of the expression tree of the abtraction's body. This operation is captured by the simple operational semantics of each of the three RETURN instructions. Namely, when executing a RETURN instruction, the runtime performs the following three-step procedure; it
However, it is also often desirable, under certain circumstances, that
computation may not be let to proceed further at its current
level of nesting of exitable abstractions. Then, computation may
be allowed to return right away from this current nesting (i.e., as if
having fallen off this level of exitable abtraction) when the conditions
for this to happen are met. Exiting an abstraction thus must also
return a specific value that may be a function of the context. This is
what the
kernel construction:
Now, there are several notions in the above paragraphs that need some clarification. For example, what an ``exitable'' abstraction is, and why worry about a dedicated construct in the kernel language for such a notion if it does nothing more than what is done by a RETURN instruction.
First of all, from its very name
assumes that
computation has entered that from which it must exit
(with or without any value). This from thing is an
exitable abstraction; that is, the latest
-abstraction
having the property of being exitable. Not all abstractions are
exitable. For example, any abstraction that is generated as part of the
target of some other kernel expression's syntacting sugar (e.g.,
or
, and
more generally any construct that hide implicit abstractions within),
will not be deemed exitable.
Secondly, exiting with a value
means that the type
of
must be congruent with what the return type of the
abstraction being exited is. In other words:
| (3.12) |
denotes the type of the latest exitable
abstraction in the context The above scheme indicates the following necessities: