module Control.Invertible.Functor
( Functor(..)
, (<$>)
) where
import Prelude hiding ((.), Functor(..), (<$>))
import Control.Arrow (Arrow)
import Control.Category ((.))
import Data.Monoid (Endo(..))
#ifdef VERSION_semigroupoids
import Data.Semigroupoid (Semigroupoid)
#endif
import Control.Invertible.BiArrow ((^^<<), invert)
import Data.Invertible.Bijection
import Data.Invertible.Monoid (BiEndo(..))
class Functor f where
fmap :: a <-> b -> f a -> f b
(<$>) :: Functor f => a <-> b -> f a -> f b
(<$>) = fmap
infixl 4 <$>
instance (
#ifdef VERSION_semigroupoids
Semigroupoid a,
#endif
Arrow a) => Functor (Bijection a b) where
fmap = (^^<<)
instance Functor Endo where
fmap (f :<->: g) (Endo a) = Endo $ f . a . g
instance Functor BiEndo where
fmap f (BiEndo a) = BiEndo $ f . a . invert f