Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on What Color Is Your Monad. Parent comment
<exn, console, e>
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
with ctl id() resume(7) log("nice!")
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) }
7 nice!
There are no comments on this comment yet.
In the case of needing a correlation id, this is a great use case for effects! First we declare an effect type:
Then we set up a handler: 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:
Which, using the above handler, would print: For example. Hope this helps!