scala - How to find out what happens when I use Monoid for Map in scalaz -
how can find instances of
monoid
. example, how know if theremonoid
instancemap
in scalaz ? , if yes, in source code. i've tried following without success@ implicitly[monoid[map[_, _]]] main.scala:1146: not find implicit value parameter e: scalaz.monoid[map[_, _]] implicitly[monoid[map[_, _]]] ^ compilation failed
how can see happens (implicit conversions, …) when execute code repl, like
map("a", 1) |+| map("a", 1)
there no way find instances of type class.
specifically
map
depends on type of values, becausemap[k, v]
monoid instance needssemigroup[v]
instance.you can find code
map
'smonoid
inscalaz.std.map
.you can see implicit conversions using reflection :
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)))
the scalaz implicits @ work :
- the syntax conversion
tosemigroupops
add|+|
operationmap
. - the
monoid
instancemap[string, int]
usessemigroup[int]
instance.
- the syntax conversion
Comments
Post a Comment