Last active
May 11, 2016 03:29
-
-
Save taisukeoe/aeb24f8b40adfe4c1c6daf671414ae61 to your computer and use it in GitHub Desktop.
CofreeEqual with Implicit Function Types?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```scala | |
implicit def cofreeEqual[A, F[_]](implicit A: Equal[A], F: Equal[F[Cofree[F, A]]]): Equal[Cofree[F, A]] = | |
Equal.equal{ (a, b) => | |
A.equal(a.head, b.head) && F.equal(a.tail, b.tail) | |
} | |
scala> import scalaz._,Scalaz._ | |
import scalaz._ | |
import Scalaz._ | |
scala> Cofree.cofreeEqual[Int, Option] | |
<console>:14: error: diverging implicit expansion for type scalaz.Equal[Option[scalaz.Cofree[Option,Int]]] | |
starting with method optionEqual in trait OptionInstances0 | |
Cofree.cofreeEqual[Int, Option] | |
^ | |
``` | |
might be resolved by "implicit function types", something like: | |
```scala | |
type CofreeEqual[A, F[_]] = implicit Equal[A] => implicit Equal[F[Cofree[F, A]]] => Equal[Cofree[F, A]] | |
implicit def cofreeEqual[A, F[_]]: CofreeEqual[A,F[_]] = | |
implicitly[Equal[A]].equal{ (a, b) => | |
A.equal(a.head, b.head) && implicitly[Equal[F[Cofree[F,A]]]].equal(a.tail, b.tail) | |
} | |
``` | |
referring to @xuwei_k 's blog post: | |
http://d.hatena.ne.jp/xuwei/20131223/1387798959 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment