-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/implicits #69
Conversation
With first class implicit handlers we now can write code like // forall<a,e>. (() -> <?x|e> a) -> e a
val x = implicit (?x = 3)
// forall<a,e>. (() -> <?x,?y|e> a) -> e a
val xy = implicit (?x = 3, ?y = 4)
effect reader<a> { fun read() : a }
// forall<a,e>. (() -> <?x,reader<int>|e> a) -> e a
val read42 = implicit (read = 42, ?x = read())
val res2 = {
using implicit (?x = 3)
?x + ?x
} EDIT: This syntax is mostly deprecated as the proposal moved on. |
With the new lazy implicit handler declarations, we can write code like: implicit (?x = { println("asked for x"); 42 }) { ?x + ?x } which will evaluate the body in braces every time the implicit argumentis being used. However, note that this is driven syntactically and thus is not equal to fun getX() { println("asked for x"); 42 }
implicit (?x = getX) { ?x + ?x } which will bind the function In contrast ...
implicit (?x = getX()) { ?x + ?x } will be eagerly evaluated and trigger the side effects once. EDIT: This syntax is mostly deprecated as the proposal moved on. |
4c0aaca
to
5c87b87
Compare
The latest changes now allow syntax like the following: effect dimensions {
val width : int
val height : int
}
implicit fun test(a: int): int
implicit val test2: int
val h = handler {
fun test2() { 42 }
}
val h2 = handler {
val test2 = 43
} Still missing:
|
@daanx The latest commit (e3f96ab) introduced the biggest breaking change: Dynamically bound functions are tail resumptive per default. (edit: commit a3ccdf6 now also adjusts the tests accordingly) handler {
fun op() { /* ... no resume here ... */ }
} To actually get access to the continuation we now need to prefix the function with handler {
effect fun op() { /* ... resume now available ... */ }
} Right now, this change prevents changing the state of a parametrized handler in a dynamically bound function (since resume is not available). To change the state, the |
Using |
85e75f8
to
c6bae47
Compare
…s div effects; state isolation only happens now at *named* function generalization
This PR encodes implicit parameters using algebraic effects.
PR for discussion. Replaces #68. See original PR for more discussion.