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

Cats instances should not require lazy val #68

Open
Avasil opened this issue Jan 11, 2020 · 0 comments
Open

Cats instances should not require lazy val #68

Avasil opened this issue Jan 11, 2020 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Avasil
Copy link
Contributor

Avasil commented Jan 11, 2020

When I changed instances of typeclasses to be shared in #67
e.g.

/** Global instance for `cats.CommutativeApplicative`
  */
implicit def commutativeApplicative[E]: CommutativeApplicative[BIO.Par[E, ?]] =
  commutativeApplicativeAny.asInstanceOf[CommutativeApplicative[BIO.Par[E, ?]]]

private[this] final lazy val commutativeApplicativeAny: CommutativeApplicative[BIO.Par[Any, ?]] =
  catsParallelAny.applicative

I had to do lazy val instead of a val, even if this val was unused. Otherwise BIO couldn't be initialized. It works for some of the instances though, e.g.

implicit def timer[E]: Timer[BIO[E, ?]] =
  timerAny.asInstanceOf[Timer[BIO[E, ?]]]

private[this] final val timerAny: Timer[BIO[Any, ?]] =
  new Timer[BIO[Any, ?]] {
    override def sleep(duration: FiniteDuration): BIO[Any, Unit] =
      BIO.sleep(duration)

    override def clock: Clock[BIO[Any, ?]] =
      BIO.clock
  }

I feel like the only difference is that the instance is created in the same file but I don't know why does it cause a difference.

@Avasil Avasil added bug Something isn't working help wanted Extra attention is needed labels Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant