Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
trepidacious
@trepidacious
Contravariance is the other way around, say you have a class that accepts instances of A - in that case if it can accept any A, and B <: A, it can accept any B as well (because every B is an A). So we have Target[A] is a Target[B] if B <: A.
Now you have Store[T <: Burger] - that says nothing about the variance (co or contra) of Store at all - it just says that you can only define a Store[T] if T <: Burger, i.e. for some type T that is a Burger.
Your original definition class Store[+T <: Burger] means "A store has a type parameter T, which must be some kind of Burger, and a Store[A] can be treated as a Store[B] as long as A is a B". So for example a Store[SuperFancyBurger] is still a Store[Burger], but we do need to know that SuperFancyBurger <: Burger. However you can't make a Store[Pizza] because Pizza is not a type of Burger.
Wow those explanations were rambling and terrible, I apologise. Hopefully some of that makes sense.
RAJKUMAR NATARAJAN
@rajcspsg
Hi
I'm trying to create Show instance for my custom config
I'm trying to use import cats.derived.semi from "org.typelevel" %% "kittens" % "1.2.0"
The complete code is
    import enumeratum.{Enum, EnumEntry}

    sealed abstract class AppEnvironment extends EnumEntry

    object AppEnvironment extends Enum[AppEnvironment] {
    case object Local extends AppEnvironment
    case object Testing extends AppEnvironment
    case object Production extends AppEnvironment

    override val values: Vector[AppEnvironment] =
        findValues.toVector
    }

    import java.net.InetAddress
    import scala.concurrent.duration.Duration

    final case class ApiConfig(host: InetAddress, port: Int, apiKey: String, timeout: Duration)

    import java.net.InetAddress
    import cats.Show
    import cats.derived.semi
    import ciris.config.loader.AppEnvironment.{Local, Production, Testing}
    import enumeratum.EnumEntry
    import eu.timepit.refined.auto._
    import eu.timepit.refined.types.string.NonEmptyString
    import scala.concurrent.duration._

    final case class Config(appName: NonEmptyString, environment: AppEnvironment, api: ApiConfig)

    object Config {
    implicit val showConfig: Show[Config] = {
        implicit val showDuration: Show[Duration] =
        Show.fromToString

        implicit val showInetAddress: Show[InetAddress] =
        Show.fromToString

        implicit def showEnumEntry[E <: EnumEntry]: Show[E] =
        Show.show(_.entryName)

        // Show.show[Config](x => s"api = ${x.api} appName = ${x.appName} environment ${x.environment}")
        semi.show
        }
    }
The compiler error I'm getting is -
        [error] /Users/rajkumar.natarajan/Documents/Coding/kafka_demo/circe-demo/src/main/scala/ciris/config/loader/Config.scala:32:5: ambiguous implicit values:
        [error]  both value emptyProductDerivedShow in trait MkShowDerivation of type => cats.derived.MkShow[shapeless.HNil]
        [error]  and method emptyCoproductDerivedShow in trait MkShowDerivation of type => cats.derived.MkShow[shapeless.CNil]
        [error]  match expected type cats.derived.MkShow[A]
        [error]     show
        [error]     ^
        [error] one error found
        [error] (Compile / compileIncremental) Compilation failed
        [error]
RAJKUMAR NATARAJAN
@rajcspsg
Any idea how can I resolve this error ?
charlesres
@charlesres
Try deleting the implicit for showDuration. I believe an instance was added with this github issue (typelevel/cats#2216), so you might have two instances. I was able to compile the code, so let me know if not.
@rajcspsg
Forgot to mention to add import cats.implicits._
Abhishek Srivastava
@abhishes_twitter
Hello, How do I convert a Map[String, ConnectionIO[List[Foo]]] into ConnectionIO[Map[String, List[Foo]]]. Here connection IO is a monad used by doobie.
Rob Norris
@tpolecat
Probably the easiest way is to add alleycats-core and import alleycats.std.map._ and then you can say .sequence
It's not strictly lawful because map traversal isn't congruent with equality and you can observe this with the Traverse instance. But it usually doesn't matter.
Abhishek Srivastava
@abhishes_twitter
great @tpolecat let me try this out. didn't know about alleycats :)
Minh Thai
@mt40
hi, anyone know where can I buy a physical copy of the book Scala with Cats?
Rob Norris
@tpolecat
@noelwelsh and/or @davegurnell ^^
Adam Rosien
@arosien
@mt40 we occasionally print copies of the books, but we don't currently have a way to publish on demand. sorry!
the book is free, so if you really wanted to, you could get it printed
Ryan Zeigler
@rzeigler
So, lets say I have a tagless encoding and I would like to add a localized state effect. The easy way is just to stack a StateT on top of my F, but if I wanted to use something like meow-mtl, does anyone know might I go about doing it? The only thing I can think of introducing some additional typeclass that knows how to convert F ~> G to add the state effect with a function receives a by name G[A] and an initial S returning an F[A]. This seems straightforward, but there doesn't seem to be a great way of introducing multiple local effects and seems generally kind of awkward. Does anyone have any pointers on a way of doing it?
Fabio Labella
@SystemFw
A couple of thoughts:
  • there are cases in which lack of higher-rank types and implicit function types really hurts, and you are forced to stick with concrete types
  • I don't see how F ~> G comes into place in this specific scenario
@rzeigler
My gut feeling is that you're in case no 1 and need both higher ranks and implicit function types, in which case I'd recommend just using the transformer locally instead (so StateT in this case). Anyway a small example would help
Ryan Zeigler
@rzeigler
So, I don't actually need the performance, I was just trying to figure out how to do it
The F, and G came into play, because there could be generally F and G = StateT[F, S, ?] which gives me G: MonadState, alternatively, the meow-mtl ref constructs all F = IO and G = IO and there's just an implicit MonadState floating around that works for "G"
Ryan Zeigler
@rzeigler
maybe the solution is just have a specific wrapper that knows how to bootstrap a state context for a set of operations and then delegates to some abstract implementation that requires the effect types. Then, the bootstrapper can be specialized for the base F type and the logical piece remains generic.
Jakub Kozłowski
@kubukoz
if you're using meow-mtl, you don't need a G
I mean... you can have a MonadState for your F that is IO
created from a Ref[IO]
alternatively you can have MonadState for F and F = StateT[IO
Ryan Zeigler
@rzeigler
yes, what I was trying to figure out how to do was introduce MonadState for any F locally while using meow-mtl when F = IO but keeping the encapsulating code unaware over the distinction
so, in that scenario, F might be G if you are using IO, but otherwise it won't
Jakub Kozłowski
@kubukoz
ok, I see what you're trying to do
btw. does this work?
      def localState[A](initial: S)(runState: MonadState[IO, S] => IO[A]): IO[A] =
        Ref[IO].of(initial).flatMap(_.runState(runState))
ah runState is from meow
right
Fabio Labella
@SystemFw

so, I don't actually need the performance, I was just trying to figure out how to do it

I'm not talking about perf at all, just expressiveness

Nick Telford
@nicktelford
Hi everyone, does anyone have any tips on how to debug diverging implicit expansions? The default compiler output isn't particularly helpful.
Fabio Labella
@SystemFw
I can tell you what the error is in 99% of the cases (unless you're using shapeless)
there's some method that needs an explicit type ascription like foo[F] somewhere
you can find it by finding a method that has a type parameter that then appears only in an implicit parameter list
for example def write[F[_]](a: String)(implicit F: Thing[F])
Nick Telford
@nicktelford
ahh, so it's usually caused by a type inference issue rather than a recursive implicit search?
@SystemFw what if that method itself is implicit :D