How to find out what happens when I use Monoid for Map in scalaz

  • How to find all instances Monoid. For example, how do you know if there is an instance Monoidfor Mapin scalaz? And if so, where is it in the source code. I tried the following without success

    @ implicitly[Monoid[Map[_, _]]]
    Main.scala:1146: could not find implicit value for parameter e: scalaz.Monoid[Map[_, _]]
    implicitly[Monoid[Map[_, _]]]
              ^
    Compilation Failed
    
  • How can I see what happens (implicit conversions, ...) when I execute code from REPL, for example

    Map("a", 1) |+| Map("a", 1)
    
+4
source share
1 answer
  • Unable to find all instances of type class.

    In particular, Mapthis depends on the type of values, because a monoid Map[K, V]instance needs an instance Semigroup[V].

    Code Map Monoidcan be found at scalaz.std.map.

  • :

    import scalaz.std.map._
    import scalaz.std.anyVal._
    import scalaz.syntax.semigroup._
    
    import scala.reflect.runtime.universe._
    
    showCode(reify { Map("a" -> 1) |+| Map("a" -> 1)  }.tree)
    // `package`.monoid.ToSemigroupOps(
    //   Predef.Map.apply(Predef.ArrowAssoc("a").->(1)))
    //   (map.mapMonoid(Predef.this.DummyImplicit.dummyImplicit, anyVal.intInstance))
    //   .|+|(Predef.Map.apply(Predef.ArrowAssoc("a").->(1)))
    

    Scala :

    • ToSemigroupOps, |+| Map.
    • Monoid Map[String, Int], Semigroup[Int].
+5

All Articles