ekmett / bifunctors

Haskell 98 bifunctors, bifoldables and bitraversables
Other
57 stars 42 forks source link

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

Open Icelandjack opened 1 year ago

Icelandjack commented 1 year ago

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.

Icelandjack commented 1 year ago

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
Topsii commented 1 year ago

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