-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | a mirror image of some standard type classes, with methods of rank 2 types -- -- A mirror image of the standard constructor type class hierarchy rooted -- in Functor, except with methods of rank 2 types and class -- instances of kind (*->*)->*. The classes enable generic -- handling of heterogenously typed data structures and other neat -- tricks. @package rank2classes @version 0.2 -- | Import this module qualified, like this: -- --
--   import qualified Rank2
--   
-- -- This will bring into scope the standard classes Functor, -- Applicative, Foldable, and Traversable, but with -- a Rank2. prefix and a twist that their methods operate on a -- heterogenous collection. The same property is shared by the two less -- standard classes Apply and Distributive. module Rank2 -- | Equivalent of Functor for rank 2 data types class Functor g (<$>) :: Functor g => (forall a. p a -> q a) -> g p -> g q -- | Subclass of Functor halfway to Applicative -- --
--   (.) <$> u <*> v <*> w == u <*> (v <*> w)
--   
class Functor g => Apply g where (<*>) = liftA2 apply liftA2 f g h = (Arrow . f) <$> g <*> h liftA3 f g h i = liftA2 (\ p q -> Arrow (f p q)) g h <*> i -- | Equivalent of <*> for rank 2 data types (<*>) :: Apply g => g (Arrow p q) -> g p -> g q -- | Equivalent of liftA2 for rank 2 data types liftA2 :: Apply g => (forall a. p a -> q a -> r a) -> g p -> g q -> g r -- | Equivalent of liftA3 for rank 2 data types liftA3 :: Apply g => (forall a. p a -> q a -> r a -> s a) -> g p -> g q -> g r -> g s -- | Equivalent of Applicative for rank 2 data types class Apply g => Applicative g pure :: Applicative g => (forall a. f a) -> g f -- | Equivalent of Foldable for rank 2 data types class Foldable g foldMap :: (Foldable g, Monoid m) => (forall a. p a -> m) -> g p -> m -- | Equivalent of Traversable for rank 2 data types class (Functor g, Foldable g) => Traversable g where traverse f = sequence . fmap (Compose . f) sequence = traverse getCompose traverse :: (Traversable g, Applicative m) => (forall a. p a -> m (q a)) -> g p -> m (g q) sequence :: (Traversable g, Applicative m) => g (Compose m p) -> m (g p) -- | Equivalent of Distributive for rank 2 data types class DistributiveTraversable g => Distributive g where collect f = distribute . fmap f distribute = distributeWith Compose collect :: (Distributive g, Functor f1) => (a -> g f2) -> f1 a -> g (Compose f1 f2) distribute :: (Distributive g, Functor f1) => f1 (g f2) -> g (Compose f1 f2) distributeWith :: (Distributive g, Functor f1) => (forall x. f1 (f2 x) -> f x) -> f1 (g f2) -> g f -- | A weaker Distributive that requires Traversable to use, -- not just a Functor. class Functor g => DistributiveTraversable (g :: (k -> *) -> *) where collectTraversable f = distributeTraversable . fmap f distributeTraversable = distributeWithTraversable Compose distributeWithTraversable = distributeWith collectTraversable :: (DistributiveTraversable g, Traversable f1) => (a -> g f2) -> f1 a -> g (Compose f1 f2) distributeTraversable :: (DistributiveTraversable g, Traversable f1) => f1 (g f2) -> g (Compose f1 f2) distributeWithTraversable :: (DistributiveTraversable g, Traversable f1) => (forall x. f1 (f2 x) -> f x) -> f1 (g f2) -> g f distributeWithTraversable :: (DistributiveTraversable g, Traversable f1, Distributive g) => (forall x. f1 (f2 x) -> f x) -> f1 (g f2) -> g f -- | A variant of distribute convenient with Monad instances distributeJoin :: (Distributive g, Monad f) => f (g f) -> g f -- | Right-to-left composition of functors. The composition of applicative -- functors is always applicative, but the composition of monads is not -- always a monad. newtype Compose k k1 (f :: k1 -> *) (g :: k -> k1) (a :: k) :: forall k k1. (k1 -> *) -> (k -> k1) -> k -> * Compose :: f (g a) -> Compose k k1 [getCompose] :: Compose k k1 -> f (g a) -- | A rank-2 equivalent of '()', a zero-element tuple data Empty f Empty :: Empty f -- | A rank-2 tuple of only one element newtype Only a f Only :: f a -> Only a f [fromOnly] :: Only a f -> f a -- | Equivalent of Identity for rank 2 data types newtype Identity g f Identity :: g f -> Identity g f [runIdentity] :: Identity g f -> g f -- | Equivalent of Product for rank 2 data types data Product g h f Pair :: g f -> h f -> Product g h f [fst] :: Product g h f -> g f [snd] :: Product g h f -> h f -- | Wrapper for functions that map the argument constructor type newtype Arrow p q a Arrow :: (p a -> q a) -> Arrow p q a [apply] :: Arrow p q a -> p a -> q a -- | Alphabetical synonym for <*> ap :: Apply g => g (Arrow p q) -> g p -> g q -- | Alphabetical synonym for <$> fmap :: Functor g => (forall a. p a -> q a) -> g p -> g q -- | Equivalent of liftA3 for rank 2 data types liftA3 :: Apply g => (forall a. p a -> q a -> r a -> s a) -> g p -> g q -> g r -> g s liftA4 :: Apply g => (forall a. p a -> q a -> r a -> s a -> t a) -> g p -> g q -> g r -> g s -> g t liftA5 :: Apply g => (forall a. p a -> q a -> r a -> s a -> t a -> u a) -> g p -> g q -> g r -> g s -> g t -> g u -- | Like fmap, but traverses over its argument fmapTraverse :: (DistributiveTraversable f, Traversable g) => (forall a. g (t a) -> u a) -> g (f t) -> f u -- | Like liftA2, but traverses over its first argument liftA2Traverse1 :: (Apply f, DistributiveTraversable f, Traversable g) => (forall a. g (t a) -> u a -> v a) -> g (f t) -> f u -> f v -- | Like liftA2, but traverses over its second argument liftA2Traverse2 :: (Apply f, DistributiveTraversable f, Traversable g) => (forall a. t a -> g (u a) -> v a) -> f t -> g (f u) -> f v -- | Like liftA2, but traverses over both its arguments liftA2TraverseBoth :: (Apply f, DistributiveTraversable f, Traversable g1, Traversable g2) => (forall a. g1 (t a) -> g2 (u a) -> v a) -> g1 (f t) -> g2 (f u) -> f v -- | Equivalent of cotraverse for rank 2 data types cotraverse :: (Distributive g, Functor f) => (forall i. f (a i) -> b i) -> f (g a) -> g b -- | Equivalent of cotraverse for rank 2 data types using -- traversable cotraverseTraversable :: (DistributiveTraversable g, Traversable f) => (forall i. f (a i) -> b i) -> f (g a) -> g b instance forall k (g :: k -> *) k1 (a :: k1) (f :: k1 -> k). GHC.Show.Show (g (f a)) => GHC.Show.Show (Rank2.Flip g a f) instance forall k (g :: k -> *) k1 (a :: k1) (f :: k1 -> k). GHC.Classes.Ord (g (f a)) => GHC.Classes.Ord (Rank2.Flip g a f) instance forall k (g :: k -> *) k1 (a :: k1) (f :: k1 -> k). GHC.Classes.Eq (g (f a)) => GHC.Classes.Eq (Rank2.Flip g a f) instance forall k (g :: k -> *) (h :: k -> *) (f :: k). (GHC.Show.Show (h f), GHC.Show.Show (g f)) => GHC.Show.Show (Rank2.Product g h f) instance forall k (g :: k -> *) (h :: k -> *) (f :: k). (GHC.Classes.Ord (h f), GHC.Classes.Ord (g f)) => GHC.Classes.Ord (Rank2.Product g h f) instance forall k (g :: k -> *) (h :: k -> *) (f :: k). (GHC.Classes.Eq (h f), GHC.Classes.Eq (g f)) => GHC.Classes.Eq (Rank2.Product g h f) instance forall k (g :: k -> *) (f :: k). GHC.Show.Show (g f) => GHC.Show.Show (Rank2.Identity g f) instance forall k (g :: k -> *) (f :: k). GHC.Classes.Ord (g f) => GHC.Classes.Ord (Rank2.Identity g f) instance forall k (g :: k -> *) (f :: k). GHC.Classes.Eq (g f) => GHC.Classes.Eq (Rank2.Identity g f) instance forall k (a :: k) (f :: k -> *). GHC.Show.Show (f a) => GHC.Show.Show (Rank2.Only a f) instance forall k (a :: k) (f :: k -> *). GHC.Classes.Ord (f a) => GHC.Classes.Ord (Rank2.Only a f) instance forall k (a :: k) (f :: k -> *). GHC.Classes.Eq (f a) => GHC.Classes.Eq (Rank2.Only a f) instance forall k (f :: k). GHC.Show.Show (Rank2.Empty f) instance forall k (f :: k). GHC.Classes.Ord (Rank2.Empty f) instance forall k (f :: k). GHC.Classes.Eq (Rank2.Empty f) instance forall k k1 (g :: k1 -> *) (f :: k -> k1) (a :: k). GHC.Base.Monoid (g (f a)) => GHC.Base.Monoid (Rank2.Flip g a f) instance forall k (g :: * -> *) (a :: k). GHC.Base.Functor g => Rank2.Functor (Rank2.Flip g a) instance forall k (g :: * -> *) (a :: k). GHC.Base.Applicative g => Rank2.Apply (Rank2.Flip g a) instance forall k (g :: * -> *) (a :: k). GHC.Base.Applicative g => Rank2.Applicative (Rank2.Flip g a) instance forall k (g :: * -> *) (a :: k). Data.Foldable.Foldable g => Rank2.Foldable (Rank2.Flip g a) instance forall k (g :: * -> *) (a :: k). Data.Traversable.Traversable g => Rank2.Traversable (Rank2.Flip g a) instance Rank2.Functor Rank2.Empty instance forall k (a :: k). Rank2.Functor (Rank2.Only a) instance forall k (g :: (k -> *) -> *). Rank2.Functor g => Rank2.Functor (Rank2.Identity g) instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Functor g, Rank2.Functor h) => Rank2.Functor (Rank2.Product g h) instance Rank2.Foldable Rank2.Empty instance forall k (x :: k). Rank2.Foldable (Rank2.Only x) instance forall k (g :: (k -> *) -> *). Rank2.Foldable g => Rank2.Foldable (Rank2.Identity g) instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Foldable g, Rank2.Foldable h) => Rank2.Foldable (Rank2.Product g h) instance Rank2.Traversable Rank2.Empty instance forall k (x :: k). Rank2.Traversable (Rank2.Only x) instance forall k (g :: (k -> *) -> *). Rank2.Traversable g => Rank2.Traversable (Rank2.Identity g) instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Traversable g, Rank2.Traversable h) => Rank2.Traversable (Rank2.Product g h) instance Rank2.Apply Rank2.Empty instance forall k (x :: k). Rank2.Apply (Rank2.Only x) instance forall k (g :: (k -> *) -> *). Rank2.Apply g => Rank2.Apply (Rank2.Identity g) instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Apply g, Rank2.Apply h) => Rank2.Apply (Rank2.Product g h) instance Rank2.Applicative Rank2.Empty instance forall k (x :: k). Rank2.Applicative (Rank2.Only x) instance forall k (g :: (k -> *) -> *). Rank2.Applicative g => Rank2.Applicative (Rank2.Identity g) instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Applicative g, Rank2.Applicative h) => Rank2.Applicative (Rank2.Product g h) instance Rank2.DistributiveTraversable Rank2.Empty instance forall k (x :: k). Rank2.DistributiveTraversable (Rank2.Only x) instance forall k (g :: (k -> GHC.Types.*) -> GHC.Types.*). Rank2.DistributiveTraversable g => Rank2.DistributiveTraversable (Rank2.Identity g) instance forall k (g :: (k -> GHC.Types.*) -> GHC.Types.*) (h :: (k -> GHC.Types.*) -> GHC.Types.*). (Rank2.DistributiveTraversable g, Rank2.DistributiveTraversable h) => Rank2.DistributiveTraversable (Rank2.Product g h) instance Rank2.Distributive Rank2.Empty instance forall k (x :: k). Rank2.Distributive (Rank2.Only x) instance forall k (g :: (k -> GHC.Types.*) -> GHC.Types.*). Rank2.Distributive g => Rank2.Distributive (Rank2.Identity g) instance forall k (g :: (k -> GHC.Types.*) -> GHC.Types.*) (h :: (k -> GHC.Types.*) -> GHC.Types.*). (Rank2.Distributive g, Rank2.Distributive h) => Rank2.Distributive (Rank2.Product g h) -- | This module exports the templates for automatic instance deriving of -- Rank2 type classes. The most common way to use it would be -- --
--   import qualified Rank2.TH
--   data MyDataType = ...
--   $(Rank2.TH.deriveAll ''MyDataType)
--   
-- -- or, if you're picky, you can invoke only deriveFunctor and -- whichever other instances you need instead. module Rank2.TH deriveAll :: Name -> Q [Dec] deriveFunctor :: Name -> Q [Dec] deriveApply :: Name -> Q [Dec] deriveApplicative :: Name -> Q [Dec] deriveFoldable :: Name -> Q [Dec] deriveTraversable :: Name -> Q [Dec] deriveDistributive :: Name -> Q [Dec] deriveDistributiveTraversable :: Name -> Q [Dec]