lampepfl / monadic-reflection

106 stars 8 forks source link

Limitation is not in README #2

Open hiroshi-cl opened 2 years ago

hiroshi-cl commented 2 years ago

Thank you for your smart and interesting implementation, which uses context abstraction, Project Loom's coroutines and no CPS transformation.

However, there is a point which concerns me. Some type of monads, such as list monad, does not work well, since a coroutine can simulate only an "affine" delimited continuation, which can be used at most once.

An example using Scalaz follows:

    val list: List[Int] = reify [List] in {
      val l = List(1, 2, 3).flatMap(x => List(x + 5)).reflect
      val k = List(2, 3, 4).reflect
      l * k
    }

    println(list)
[error] (run-main-0) java.lang.IllegalStateException: Continuation terminated
[error] java.lang.IllegalStateException: Continuation terminated
[error]     at java.base/java.lang.Continuation.run(Continuation.java:286)
[error]     at monadic.Coroutine.resume(Coroutine.scala:19)
[error]     at monadic.Monadic.step$1(Monadic.scala:49)
[error]     at monadic.Monadic.run$2$$anonfun$1(Monadic.scala:61)
[error]     at monadic.ScalazMonadic.sequence$$anonfun$2$$anonfun$1(examples.scala:14)
...

Would you write this limitation in README? Thank you.

b-studios commented 2 years ago

Yes, good point. Loom is one-shot only, so that is the best we can do at the moment, sadly.