Interesting. What language is a good example of having effect sets? Koka?
What about the case of needing context like “correlation id,” from the article? Can that be modeled as an effect?
What about the case of needing context like “correlation id,” from the article? Can that be modeled as an effect?
<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!