Skip to content
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

scalaz.syntax.all._ doesn't work for MonadState/MonadError implicit parameters list. #2024

Open
kczulko opened this issue Oct 31, 2018 · 1 comment
Labels
scalaz7 Scalaz 7.x

Comments

@kczulko
Copy link

kczulko commented Oct 31, 2018

Hi,

I made an example app here: https://github.com/kczulko/scalaz-mtl-issue showing what's the problem.

When I create a function like this:

def dummyProgram[F[_]](implicit ME: MonadError[F,Throwable], MS: MonadState[F,Int]): F[Unit] = {
    for {
      i      <- MS.get
      _      <- MS.put(i + 1)
      result <- if (i < 0) ME.raiseError(new Throwable(":/")) else ME.point(())
    } yield result
  }

and try to materialize it with the following code:

  def main(args: Array[String]): Unit = {
    implicit val etme = EitherT.eitherTMonadError[Id,Throwable]
    implicit val stms = StateT.stateTMonadState[Int, EitherT[Id,Throwable,?]]
    implicit val stme = StateT.stateTMonadError[Int,EitherT[Id,Throwable,?],Throwable]

    dummyProgram[StateT[EitherT[Id,Throwable,?],Int,?]]
      .run(2)
      .run
      .fold(l => println(s"error: $l"), r => println(s"success $r"))
  }

Program doesn't compile with the first error of: value flatMap is not a member of type parameter F[Int]

But when I move MS as explicit parameter:

def dummyProgram[F[_]](MS: MonadState[F,Int])(implicit ME: MonadError[F,Throwable]): F[Unit] = ...

and call the program appropriately:

dummyProgram[StateT[EitherT[Id,Throwable,?],Int,?]](stms)

it compiles.

Am I doing sth wrong here?
Thanks in advance,
Karol

scalaz version: 7.2.26

~$ java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-1ubuntu0.16.04.1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
@xuwei-k
Copy link
Member

xuwei-k commented Nov 1, 2018

#1110 ?

@xuwei-k xuwei-k added the scalaz7 Scalaz 7.x label Nov 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scalaz7 Scalaz 7.x
Projects
None yet
Development

No branches or pull requests

2 participants