I'm looking to see if there is a standard typeclass for a Bi-Functor that has one Contravariant parameter and one Covariant parameter.
punching the signature (c -> a) -> (b -> d) -> f a b -> f c d
results in nothing that matches.
Basically in Scala I'm looking to do:
trait CoContraBiFunctor[F[_, _]] {
def ccmap[A, B, C, D](fab: F[A, B])(f: C => A)(g: B => D): F[C, D]
}
implicit val ccFunction: CoContraBiFunctor[Function1] = new CoContraBiFunctor[Function] {
override def ccmap[A, B, C, D](fab: Function[A, B])(f: C => A)(g: B => D): Function[C, D] = new Function[C, D] {
override def apply(c: C): D = g(fab(f(c)))
}
}
Anyone have an idea? I definitely am not the first person to look for this.
This is called a profunctor! It is a very useful type of bifunctor that shows up all over the place (for example, in the construction of lenses)! In Haskell it is available as Data.Profunctor
in the profunctors
package. I am not a Scala person but it looks like it is available in cats
as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With