-- 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.1 -- | 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 -- | 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 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 Functor g => Distributive g where collect f = distribute . fmap f distribute = distributeWith Compose distributeM = distributeWith join 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 distributeM :: (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 -- | A rank-2 tuple of only one element newtype Only a (f :: * -> *) Only :: f a -> Only a [fromOnly] :: Only a -> f a -- | Equivalent of Identity for rank 2 data types newtype Identity g (f :: * -> *) Identity :: g f -> Identity g [runIdentity] :: Identity g -> g f -- | Equivalent of Product for rank 2 data types data Product g h (f :: * -> *) Pair :: g f -> h f -> Product g h [fst] :: Product g h -> g f [snd] :: Product g h -> 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 instance GHC.Show.Show (g (f a)) => GHC.Show.Show (Rank2.Flip g a f) instance GHC.Classes.Ord (g (f a)) => GHC.Classes.Ord (Rank2.Flip g a f) instance GHC.Classes.Eq (g (f a)) => GHC.Classes.Eq (Rank2.Flip g a f) instance (GHC.Show.Show (h f), GHC.Show.Show (g f)) => GHC.Show.Show (Rank2.Product g h f) instance (GHC.Classes.Ord (h f), GHC.Classes.Ord (g f)) => GHC.Classes.Ord (Rank2.Product g h f) instance (GHC.Classes.Eq (h f), GHC.Classes.Eq (g f)) => GHC.Classes.Eq (Rank2.Product g h f) instance GHC.Show.Show (g f) => GHC.Show.Show (Rank2.Identity g f) instance GHC.Classes.Ord (g f) => GHC.Classes.Ord (Rank2.Identity g f) instance GHC.Classes.Eq (g f) => GHC.Classes.Eq (Rank2.Identity g f) instance GHC.Show.Show (f a) => GHC.Show.Show (Rank2.Only a f) instance GHC.Classes.Ord (f a) => GHC.Classes.Ord (Rank2.Only a f) instance GHC.Classes.Eq (f a) => GHC.Classes.Eq (Rank2.Only a f) instance GHC.Show.Show (Rank2.Empty f) instance GHC.Classes.Ord (Rank2.Empty f) instance GHC.Classes.Eq (Rank2.Empty f) instance GHC.Base.Monoid (g (f a)) => GHC.Base.Monoid (Rank2.Flip g a f) instance GHC.Base.Functor g => Rank2.Functor (Rank2.Flip g a) instance GHC.Base.Applicative g => Rank2.Apply (Rank2.Flip g a) instance GHC.Base.Applicative g => Rank2.Applicative (Rank2.Flip g a) instance Data.Foldable.Foldable g => Rank2.Foldable (Rank2.Flip g a) instance Data.Traversable.Traversable g => Rank2.Traversable (Rank2.Flip g a) instance Rank2.Functor Rank2.Empty instance Rank2.Functor (Rank2.Only a) instance Rank2.Functor g => Rank2.Functor (Rank2.Identity g) instance (Rank2.Functor g, Rank2.Functor h) => Rank2.Functor (Rank2.Product g h) instance Rank2.Foldable Rank2.Empty instance Rank2.Foldable (Rank2.Only x) instance Rank2.Foldable g => Rank2.Foldable (Rank2.Identity g) instance (Rank2.Foldable g, Rank2.Foldable h) => Rank2.Foldable (Rank2.Product g h) instance Rank2.Traversable Rank2.Empty instance Rank2.Traversable (Rank2.Only x) instance Rank2.Traversable g => Rank2.Traversable (Rank2.Identity g) instance (Rank2.Traversable g, Rank2.Traversable h) => Rank2.Traversable (Rank2.Product g h) instance Rank2.Apply Rank2.Empty instance Rank2.Apply (Rank2.Only x) instance Rank2.Apply g => Rank2.Apply (Rank2.Identity g) instance (Rank2.Apply g, Rank2.Apply h) => Rank2.Apply (Rank2.Product g h) instance Rank2.Applicative Rank2.Empty instance Rank2.Applicative (Rank2.Only x) instance Rank2.Applicative g => Rank2.Applicative (Rank2.Identity g) instance (Rank2.Applicative g, Rank2.Applicative h) => Rank2.Applicative (Rank2.Product g h) instance Rank2.Distributive Rank2.Empty instance Rank2.Distributive (Rank2.Only x) instance Rank2.Distributive g => Rank2.Distributive (Rank2.Identity g) instance (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]