Skip to content

Instantly share code, notes, and snippets.

@taisukeoe
Last active May 11, 2016 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taisukeoe/aeb24f8b40adfe4c1c6daf671414ae61 to your computer and use it in GitHub Desktop.
Save taisukeoe/aeb24f8b40adfe4c1c6daf671414ae61 to your computer and use it in GitHub Desktop.
CofreeEqual with Implicit Function Types?
```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