rssh/dotty-cps-async

How to writew own monad without runtime info in context [A: CpsMonadInstanceContext]. was: Some issue with stateful monad encoding?

Closed this issue · 1 comments

I have a stateful non-deterministic monad originally defined like this

trait Trying[State, +Result] {
  def apply(state: State): Vector[Res[State, Result]]
}
final class CpsMonadTrying[State] extends CpsMonad[[X] =>> Trying[State, X]] with CpsMonadContext[[X] =>> Trying[State, X]]

I can use it with async await fine.
I try to change it to

type Trying[State, +Result] = State => Vector[Res[State, Result]]

Then I got complains Async function with arity != 1 is not supported yet

When I am writing this CpsMonad I don't know what is CpsMonadContext for I just make up something to make it compile. I can't find any code or documents about CpsMonadContext to make myself understand

final class CpsMonadTrying[State] extends CpsMonad[[X] =>> Trying[State, X]] with CpsMonadContext[[X] =>> Trying[State, X]] {
...
  override def monad: CpsMonad[WF] = this

  override type Context = this.type

}
rssh commented

Can you write small self-containing code which illustrate the problem and which I can try to compile to understand?

About CpsMonadContext - look at this section: https://rssh.github.io/dotty-cps-async/MonadContexts.html
If you have no runtime infrastructure around context, then

final class CpsMonadTrying[State] extends CpsMonad[[X] =>> Trying[State, X]] 
                                                                 with CpsMonadInstanceContext[[X] =>> Trying[State, X]] {
...
   // note - CpsMonadInstanceContext is a type which should be mixed,  not CpsMonadContext
}

Full example can be found ...
https://github.com/rssh/dotty-cps-async/blob/master/shared/src/test/scala/cpstest/CpsContT.scala
(but it's too long, searching shorter ...