#if __GLASGOW_HASKELL__ >= 702
#endif
#if __GLASGOW_HASKELL__ >= 706
#endif
module Data.Bifunctor.Wrapped
( WrappedBifunctor(..)
) where
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif
import Data.Biapplicative
import Data.Bifoldable
import Data.Bitraversable
#if __GLASGOW_HASKELL__ < 710
import Data.Foldable
import Data.Monoid
import Data.Traversable
#endif
#if __GLASGOW_HASKELL__ >= 708
import Data.Typeable
#endif
#if __GLASGOW_HASKELL__ >= 702
import GHC.Generics
#endif
newtype WrappedBifunctor p a b = WrapBifunctor { unwrapBifunctor :: p a b }
deriving ( Eq, Ord, Show, Read
#if __GLASGOW_HASKELL__ >= 702
, Generic
#endif
#if __GLASGOW_HASKELL__ >= 708
, Generic1
, Typeable
#endif
)
#if __GLASGOW_HASKELL__ >= 702 && __GLASGOW_HASKELL__ < 708
data WrappedBifunctorMetaData
data WrappedBifunctorMetaCons
data WrappedBifunctorMetaSel
instance Datatype WrappedBifunctorMetaData where
datatypeName = const "WrappedBifunctor"
moduleName = const "Data.Bifunctor.Wrapped"
instance Constructor WrappedBifunctorMetaCons where
conName = const "WrapBifunctor"
conIsRecord = const True
instance Selector WrappedBifunctorMetaSel where
selName = const "unwrapBifunctor"
instance Generic1 (WrappedBifunctor p a) where
type Rep1 (WrappedBifunctor p a) = D1 WrappedBifunctorMetaData
(C1 WrappedBifunctorMetaCons
(S1 WrappedBifunctorMetaSel (Rec1 (p a))))
from1 = M1 . M1 . M1 . Rec1 . unwrapBifunctor
to1 = WrapBifunctor . unRec1 . unM1 . unM1 . unM1
#endif
instance Bifunctor p => Bifunctor (WrappedBifunctor p) where
first f = WrapBifunctor . first f . unwrapBifunctor
second f = WrapBifunctor . second f . unwrapBifunctor
bimap f g = WrapBifunctor . bimap f g . unwrapBifunctor
instance Bifunctor p => Functor (WrappedBifunctor p a) where
fmap f = WrapBifunctor . second f . unwrapBifunctor
instance Biapplicative p => Biapplicative (WrappedBifunctor p) where
bipure a b = WrapBifunctor (bipure a b)
WrapBifunctor fg <<*>> WrapBifunctor xy = WrapBifunctor (fg <<*>> xy)
instance Bifoldable p => Foldable (WrappedBifunctor p a) where
foldMap f = bifoldMap (const mempty) f . unwrapBifunctor
instance Bifoldable p => Bifoldable (WrappedBifunctor p) where
bifoldMap f g = bifoldMap f g . unwrapBifunctor
instance Bitraversable p => Traversable (WrappedBifunctor p a) where
traverse f = fmap WrapBifunctor . bitraverse pure f . unwrapBifunctor
instance Bitraversable p => Bitraversable (WrappedBifunctor p) where
bitraverse f g = fmap WrapBifunctor . bitraverse f g . unwrapBifunctor