{-# Language DeriveDataTypeable, FlexibleInstances, KindSignatures, MultiParamTypeClasses, RankNTypes,
StandaloneDeriving, TypeFamilies, TypeOperators, UndecidableInstances #-}
module Transformation.Shallow where
import Control.Applicative (Applicative, liftA2)
import Data.Functor.Compose (Compose)
import Data.Functor.Const (Const)
import qualified Rank2
import Transformation (Transformation, Domain, Codomain)
import Prelude hiding (Foldable(..), Traversable(..), Functor(..), Applicative(..), (<$>), fst, snd)
class (Transformation t, Rank2.Functor g) => Functor t g where
(<$>) :: t -> g (Domain t) -> g (Codomain t)
infixl 4 <$>
class (Transformation t, Rank2.Foldable g) => Foldable t g where
foldMap :: (Codomain t ~ Const m, Monoid m) => t -> g (Domain t) -> m
class (Transformation t, Rank2.Traversable g) => Traversable t g where
traverse :: Codomain t ~ Compose m f => t -> g (Domain t) -> m (g f)
instance (Functor t g, Functor t h) => Functor t (Rank2.Product g h) where
t
t <$> :: t -> Product g h (Domain t) -> Product g h (Codomain t)
<$> Rank2.Pair g (Domain t)
left h (Domain t)
right = forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Rank2.Pair (t
t forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
<$> g (Domain t)
left) (t
t forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
<$> h (Domain t)
right)
instance (Foldable t g, Foldable t h, Codomain t ~ Const m, Monoid m) => Foldable t (Rank2.Product g h) where
foldMap :: forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> Product g h (Domain t) -> m
foldMap t
t (Rank2.Pair g (Domain t)
left h (Domain t)
right) = forall t (g :: (* -> *) -> *) m.
(Foldable t g, Codomain t ~ Const m, Monoid m) =>
t -> g (Domain t) -> m
foldMap t
t g (Domain t)
left forall a. Monoid a => a -> a -> a
`mappend` forall t (g :: (* -> *) -> *) m.
(Foldable t g, Codomain t ~ Const m, Monoid m) =>
t -> g (Domain t) -> m
foldMap t
t h (Domain t)
right
instance (Traversable t g, Traversable t h, Codomain t ~ Compose m f, Applicative m) => Traversable t (Rank2.Product g h) where
traverse :: forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> Product g h (Domain t) -> m (Product g h f)
traverse t
t (Rank2.Pair g (Domain t)
left h (Domain t)
right) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Rank2.Pair (forall t (g :: (* -> *) -> *) (m :: * -> *) (f :: * -> *).
(Traversable t g, Codomain t ~ Compose m f) =>
t -> g (Domain t) -> m (g f)
traverse t
t g (Domain t)
left) (forall t (g :: (* -> *) -> *) (m :: * -> *) (f :: * -> *).
(Traversable t g, Codomain t ~ Compose m f) =>
t -> g (Domain t) -> m (g f)
traverse t
t h (Domain t)
right)
fmap :: Functor t g => t -> g (Domain t) -> g (Codomain t)
fmap :: forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
fmap = forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
(<$>)