Git Product home page Git Product logo

Comments (2)

b-studios avatar b-studios commented on July 17, 2024

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.

b-studios avatar b-studios commented on July 17, 2024

BTW, if you are benchmarking this; I would be interested to learn about your findings :)

from effekt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.