Comments (2)
I am sorry, but with the MLton backend you are working on the bleeding edge. This is indeed a known issue that we still need to address. ML does not have support for rank-2 types, which are required by our translation to system-f. We are working on #229 to avoid this.
The easiest workaround is avoiding the interaction of mutable state, recursive functions (while) and calling the continuation under the recursive function for now. This is not really satisfying and we are working on better solutions.
EDIT: I believe the issue was actually not caused by mutable state and recursive functions, but by the fact that Choice contained both effect operations choose and fail. They are naturally called at different answer types (int
and unit
, the result of the operations). MLton will try to monomorphize the evidence passed for Choice
but it cannot, because it would need to work for int
as well as unit
(this problem is dealt with in #229 -- but some other problems resurfaced there).
I slightly massaged your program manually to avoid the rank-2 problem and it should work now:
effect Choose {
def choose(n: Int): Int
}
effect Fail {
def fail(): Unit
}
effect Choice = {Choose,Fail}
effect Yield {
def yield(a: Int, b: Int, c: Int): Unit
}
def triple(n: Int, s: Int): Unit / {Choice, Yield} = {
val i = do choose(n)
val j = do choose(i - 1)
val k = do choose(j - 1)
if (i + j + k == s) {
do yield(i, j, k)
} else {
do fail()
}
}
def yieldTriples(n: Int, s: Int): Unit / {Yield} = {
try {
triple(n, s)
} with Choose {
def choose(n) = {
var i = 1;
while (i < n) {
resume(i);
i = i + 1
}
}
} with Fail {
def fail() = ()
}
}
def countTriples(n: Int, s: Int): Int = {
var cnt = 0;
try {
yieldTriples(n, s)
} with Yield {
def yield(i: Int, j: Int, k: Int) = {
cnt = cnt + 1;
resume(())
}
};
cnt
}
def main() = println(countTriples(8, 6))
from effekt.
BTW, if you are benchmarking this; I would be interested to learn about your findings :)
from effekt.
Related Issues (20)
- Unhelpful error messages when misusing block arguments
- Initializing List with [] inside a function leads to a Reference Error HOT 2
- Artifact for PLDI 2022 HOT 10
- Multiple copies of a region on the stack HOT 1
- Existential types HOT 2
- Higher-rank polymorphism HOT 3
- Multiple return values
- Unexpected Reference Error, when working with Coroutines. HOT 11
- Interface Polymorphic typing HOT 8
- Handling without control HOT 1
- `--compile` should generate executable HOT 5
- Overloading constructors breaks pattern matching
- Examples of Effect Checking are Out-of-Date
- Private definitions
- Singleton interfaces
- Import and module are implemented counterintuitive HOT 7
- Import everything from a module HOT 1
- Import and namespacing
- SML data / codata representation
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 effekt.