Comments (4)
@zaoqi-unsafe The resume function is like a callback in JavaScript.
Let's say you are using some Node.js APIs in JavaScript:
function foo(cb) {
fs.readFile("foo", function (err, data) {
fs.writeFile("bar", data, cb);
});
}
When the readFile
function is finished, it will call the callback with the file contents.
Now consider this Koka code:
fun foo(): asyncx () {
val data = read-file("foo")
write-file("bar", data)
}
The Koka compiler will translate the above code into this JavaScript:
function read_file(path, resume) {
// Do some stuff then call resume
}
function write_file(path, data, resume) {
// Do some stuff then call resume
}
function foo(resume) {
read_file("foo", function (data) {
write_file("bar", data, resume);
});
}
In other words, Koka automatically added in the callbacks for you.
When you write an effect handler, resume
is the callback.
So if read-file
never calls resume
, then the read-file
function will never return.
And if read-file
does call resume
, then the first argument to resume
is the return value for read-file
from koka.
@zaoqi-unsafe Handlers can have extra state (in this case i
). When you call resume
, the first argument is the new state, and the second argument is the return value.
So in this case i
is the current state, and resume(i,i)
keeps the current state, and resume(j,())
sets the state to j
from koka.
val state = handler(i) {
return x -> x
get() -> resume(i,i)
set(j) -> resume(j,())
}
from koka.
Thanks for answering @Pauan -- I'll go ahead and close the issue.
from koka.
Related Issues (20)
- Spec grammar is out of sync HOT 2
- Open Effect Error
- async effect HOT 1
- Program crash when parsing file HOT 3
- Unclear error message "error: identifier .Hnd-div cannot be found"
- option to use system malloc HOT 1
- Effectful vector initialization HOT 2
- Better Hover Colors
- Phantom compile errors in interactive compiler HOT 4
- REPL crashes when using :t command
- Polymorphic Effect Inference Inconsistency for Function Values Across Multiple Call Sites HOT 1
- Unintuitive Effect Inference Behavior with println in Functions Using Polymorphic Effects HOT 4
- Bitwise Operators HOT 1
- Use of `padding` identifier causes compilation errors under some circumstances HOT 6
- install.sh doesn't evaluate paths HOT 2
- VS Code Extension Errors On Activation HOT 3
- vector-init does not work correctly for control effects HOT 3
- Bytes module
- Better parser recovery for incomplete function bodies / statements.
- Add language server tests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from koka.