Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds implicits to Unapply to unpack A into [α]A #153

merged 1 commit into from Sep 21, 2012


None yet
2 participants
Copy link

commented Sep 19, 2012


currently Int => Int cannot be passed into traverseU. Int is indirectly available as Applicative via Monoid[Int].applicative, which is Applicative[[α]Int].

scala> Applicative[({type λ[α] = Int})#λ]
res0: scalaz.Applicative[[α]Int] = scalaz.Monoid$$anon$1@26b0207f

scala> List(1, 2, 3) traverseU {_ + 1}
<console>:14: error: Unable to unapply type `Int` into a type constructor of kind `M[_]` that is classified by the type class `scalaz.Applicative`
1) Check that the type class is defined by compiling `implicitly[scalaz.Applicative[<type constructor>]]`.
2) Review the implicits in object Unapply, which only cover common type 'shapes'
(implicit not found: scalaz.Unapply[scalaz.Applicative, Int])
              List(1, 2, 3) traverseU {_ + 1}

what this changes

I added unapplyA as the lowest priority implicit, which unpacks A into [α]A.

trait Unapply_3 {
  // /** Unpack a value of type `A0` into type `[a]A0`, given a instance of `TC` */
  implicit def unapplyA[TC[_[_]], A0](implicit TC0: TC[({type λ[α] = A0})#λ]): Unapply[TC, A0] {
    type M[X] = A0
    type A = A0
  } = new Unapply[TC, A0] {
    type M[X] = A0
    type A = A0
    def TC = TC0
    def apply(ma: M[A0]) = ma

With this, traverseU works as follows:

scala> List(1, 2, 3) traverseU {_ + 1}
res0: Int = 9

tonymorris added a commit that referenced this pull request Sep 21, 2012

Merge pull request #153 from eed3si9n/topic/unapplya
adds implicits to Unapply to unpack A into [α]A

@tonymorris tonymorris merged commit 8cabc17 into scalaz:scalaz-seven Sep 21, 2012

1 check passed

default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.