Skip to content

Instantly share code, notes, and snippets.

@long-long-float
Created November 22, 2020 08:24
Show Gist options
  • Save long-long-float/8e9bb03c7fbc104046a15823133d2cc2 to your computer and use it in GitHub Desktop.
Save long-long-float/8e9bb03c7fbc104046a15823133d2cc2 to your computer and use it in GitHub Desktop.
module irc
effect Connected(): Unit / { Message }
effect Message {
def message(msg: String): Int / { Response }
def reaction(id: Int, name: String): Unit / { Response }
}
effect Response {
def response(msg: String): Unit
}
record Client()
def accept { f: Client => Unit } : Unit = {
f(Client())
}
def wait(c: Client) : Unit / { Message, Console } = {
client()
}
def connect(host: String) : Unit = {
// do Connected()
()
}
def server() : Unit / { Console } = {
accept { c =>
var num_of_msg = 0
//while (true) {
try {
c.wait
}
with Message {
def message(msg) = resume { do response(msg); num_of_msg = num_of_msg + 1; num_of_msg }
def reaction(id, name) = resume { do response("React to " ++ show(id) ++ " with " ++ show(name)) }
}
//}
}
}
def client(): Unit / { Console, Message } = {
try {
connect("localhost")
var id = do message("Hello")
do reaction(id, "+1")
id = do message("World")
do reaction(id, "+1")
}
with Response {
def response(msg) = {
println("Server: " ++ show(msg))
resume(())
}
}
}
def main() = {
server()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment