module Data.Bifunctor.Clown
( Clown(..)
) where
import Control.Applicative
import Data.Biapplicative
import Data.Bifunctor.Apply
import Data.Bifoldable
import Data.Bitraversable
import Data.Foldable
import Data.Functor.Apply
import Data.Monoid
import Data.Semigroup.Bifoldable
import Data.Semigroup.Bitraversable
import Data.Semigroup.Foldable
import Data.Semigroup.Traversable
import Data.Traversable
newtype Clown f a b = Clown { runClown :: f a }
deriving (Eq,Ord,Show,Read)
instance Functor f => Bifunctor (Clown f) where
first f = Clown . fmap f . runClown
second _ = Clown . runClown
bimap f _ = Clown . fmap f . runClown
instance Functor (Clown f a) where
fmap _ = Clown . runClown
instance Applicative f => Biapplicative (Clown f) where
bipure a _ = Clown (pure a)
Clown mf <<*>> Clown mx = Clown (mf <*> mx)
instance Apply f => Biapply (Clown f) where
Clown fg <<.>> Clown xy = Clown (fg <.> xy)
instance Foldable f => Bifoldable (Clown f) where
bifoldMap f _ = foldMap f . runClown
instance Foldable (Clown f a) where
foldMap _ = mempty
instance Traversable f => Bitraversable (Clown f) where
bitraverse f _ = fmap Clown . traverse f . runClown
instance Traversable (Clown f a) where
traverse _ = pure . Clown . runClown
instance Foldable1 f => Bifoldable1 (Clown f) where
bifoldMap1 f _ = foldMap1 f . runClown
instance Traversable1 f => Bitraversable1 (Clown f) where
bitraverse1 f _ = fmap Clown . traverse1 f . runClown