-
Notifications
You must be signed in to change notification settings - Fork 0
Here
Bill Hails edited this page Mar 31, 2024
·
12 revisions
The special construct here
takes a function of one argument and passes it the current continuation as a function
so that calling the current continuation is equivalent to returning through here
.
An example may make this clearer (or might not, continuations are notoriously tricky to get your head around at first 😁)
let
fn funky(k) { k(3) }
in
3 + here fn(k) {
if (funky(k)) {
4
} else {
5
}
}
returns 6
(3 + 3
).
A continuation is first class like any other function and can be passed to other functions, stored in variables, called later etc. Simply put, continuations are first-class return statements.
The type of here
is ((#a -> #_) -> #a) -> #a
(see Type Notation for a discussion of ->
).
here
is calledcall-with-current-continuation
, orcall/cc
in other languages.
Next: Then and Back
CEKF(s) a.k.a. F Natural a.k.a F♮