Skip to content

Instantly share code, notes, and snippets.

@travisbrown
Last active December 18, 2015 09:59
Show Gist options
  • Save travisbrown/5765816 to your computer and use it in GitHub Desktop.
Save travisbrown/5765816 to your computer and use it in GitHub Desktop.

Suppose we want to lift an OptionT[List, Int] into a ReaderT[OptionT[List, _], String, Int]. The nice way (liftReaderT) currently doesn't work:

scala> List(1, 2, 3).liftM[OptionT].liftReaderT[String]
<console>:14: error: could not find implicit value for parameter F0: scalaz.UnapplyCo[scalaz.Monad,scalaz.OptionT[List,Int]]
              List(1, 2, 3).liftM[OptionT].liftReaderT[String]
                                 ^
<console>:14: error: value liftReaderT is not a member of scalaz.OptionT[List,Int]
              List(1, 2, 3).liftM[OptionT].liftReaderT[String]
                                           ^

Adding this UnapplyCo instance makes everything okay:

implicit def unapplyMFA1[TC[_[_]], F[+_], M0[F[+_], +_], A0](
  implicit TC0: TC[({ type L[x] = M0[F, x] })#L]
): UnapplyCo[TC, M0[F, A0]] {
  type M[+X] = M0[F, X]
  type A = A0
} = new UnapplyCo[TC, M0[F, A0]] {
  type M[+X] = M0[F, X]
  type A = A0
  def TC = TC0
  def leibniz = Leibniz.refl
}

I don't see any problem here. Is there a reason this isn't included, when apparently more complex instances (like the one provided by unapplyMFAB1) are?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment