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


  1. how can find instances of monoid. example, how know if there monoid instance map 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 
  2. how can see happens (implicit conversions, …) when execute code repl, like

    map("a", 1) |+| map("a", 1) 

  1. there no way find instances of type class.

    specifically map depends on type of values, because map[k, v] monoid instance needs semigroup[v] instance.

    you can find code map's monoid in scalaz.std.map.

  2. 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 |+| operation map.
    • the monoid instance map[string, int] uses semigroup[int] instance.

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -