bifunctors icon indicating copy to clipboard operation
bifunctors copied to clipboard

Functor (Foldable..) instances to Bifunctors (Bifoldable..) like Product

Open Icelandjack opened this issue 2 years ago • 2 comments

For the change of adding a superclass to Bifunctor, and later to Bifoldable and Bitraversable

  • https://github.com/haskell/core-libraries-committee/issues/91
  • https://github.com/haskell/core-libraries-committee/issues/93

we need Functor instances of Data.Bifunctor.Product and others. I tried it out and it seems enough to do deriving stock Functor.

Icelandjack avatar Sep 23 '22 10:09 Icelandjack

Functor (WrappedBifunctor p a) can probably be reduced to a forall a. Functor (p a) constraint as well since second = fmap.

instance Bifunctor p => Functor (WrappedBifunctor p a) where
  fmap f = WrapBifunctor . second f . unwrapBifunctor

Icelandjack avatar Sep 23 '22 11:09 Icelandjack

For the change of adding a superclass to Bifunctor, and later to Bifoldable and Bitraversable we need Functor instances of Data.Bifunctor.Product and others. I tried it out and it seems enough to do deriving stock Functor.

That change was already done on the main branch, which contains the unreleased major version 6 of bifunctors https://github.com/ekmett/bifunctors/blob/4f1535a2c94788c9e6d9accfca8c58ef497628c5/src/Data/Bifunctor/Product.hs#L43

The Functor instance of WrappedBifunctor currently looks like this: https://github.com/ekmett/bifunctors/blob/4f1535a2c94788c9e6d9accfca8c58ef497628c5/src/Data/Bifunctor/Wrapped.hs#L107

Topsii avatar Oct 06 '22 16:10 Topsii