3 ms·
Koka is a good example of a language having effect sets: in koka, it's called a row of effects, and is written as <exn, console, e> where single letters d
by isaacimagine 5y ago
Koka is a good example of a language having effect sets: in koka, it's called a row of effects, and is written as
<exn, console, e>
where single letters denote generic params.
In the case of needing a correlation id, this is a great use case for effects! First we declare an effect type:
effect correlation_id
ctl id(): int
Then we set up a handler:
with ctl id()
resume(7)
log("nice!")
Here we just use 7, but we could be incrementing a counter per request or something.
Then any functions that are called in this scope, when they call 'id', will receive 7:
fun log(message: string): <console, correlation_id> () {
println(id())
println(message)
}
Which, using the above handler, would print:
7
nice!
For example. Hope this helps!