Indeed that's not an instance of your Bifunctor
, since the lack of constraint allows you to pick a contravariant functor for f
and then rank2bimap
would amount roughly to implement fmap
for f
:
rank2bimap id :: (g ~> g') -> Bar f g -> Bar f g' -- covariance of f, kinda (since Bar f g = f (g Int))
type f ~> f' = (forall x. f x -> f' x)
If you add the requirement that f
and g
(optional here) be functors, then you do get a bifunctor:
rank2bimap :: (Functor f, Functor g) => (f ~> f') -> (g ~> g') -> Bar f g -> Bar f' g'
In particular, to prove the bifunctor laws, you will need the free theorem of f ~> f'
, assuming f
and f'
are functors, then n :: f ~> f'
satisfies that for all phi
, fmap phi . n = n . fmap phi
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…