-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Type composition classes & instances
--   
--   TypeCompose provides some classes &amp; instances for forms of type
--   composition, as well as some modules who haven't yet found a home.
--   
--   Please see the project wiki page:
--   <a>http://haskell.org/haskellwiki/TypeCompose</a>
--   
--   Copyright 2007-2012 by Conal Elliott; BSD3 license.
@package TypeCompose
@version 0.9.12


-- | Monads with references, taken from John Hughes's "Global Variables in
--   Haskell" (<a>http://citeseer.ist.psu.edu/473734.html</a>).
module Data.RefMonad

-- | Class of monads with references.
class Monad m => RefMonad m r | m -> r
newRef :: RefMonad m r => a -> m (r a)
readRef :: RefMonad m r => r a -> m a
writeRef :: RefMonad m r => r a -> a -> m ()

-- | Change the contents of a ref
modifyRef :: RefMonad m r => r a -> (a -> a) -> m ()
instance Data.RefMonad.RefMonad GHC.Types.IO GHC.IORef.IORef
instance Data.RefMonad.RefMonad (GHC.ST.ST s) (GHC.STRef.STRef s)


-- | Bijections. For a more general setting, see also [1] <i>There and Back
--   Again: Arrows for Invertible Programming</i>,
--   <a>http://citeseer.ist.psu.edu/alimarine05there.html</a>.
module Data.Bijection

-- | A type of bijective arrows
data Bijection j a b
Bi :: a `j` b -> b `j` a -> Bijection j a b
[biTo] :: Bijection j a b -> a `j` b
[biFrom] :: Bijection j a b -> b `j` a

-- | Bijective functions
type (:<->:) a b = Bijection (->) a b

-- | Bijective identity arrow. Warning: uses <a>arr</a> on
--   <tt>(~&gt;)</tt>. If you have no <a>arr</a>, but you have a
--   <tt>DeepArrow</tt>, you can instead use <tt>Bi idA idA</tt>.
idb :: Arrow j => Bijection j a a

-- | Inverse bijection
inverse :: Bijection j a b -> Bijection j b a

-- | Bijections on functors
bimap :: Functor f => (a :<->: b) -> (f a :<->: f b)

-- | Bijections on arrows.
(--->) :: Arrow j => Bijection j a b -> Bijection j c d -> (a `j` c) :<->: (b `j` d)
infixr 2 --->

-- | Apply a function in an alternative (monomorphic) representation.
inBi :: Arrow j => Bijection j a b -> (a `j` a) -> (b `j` b)
instance Control.Category.Category j => Control.Category.Category (Data.Bijection.Bijection j)
instance Control.Arrow.Arrow j => Control.Arrow.Arrow (Data.Bijection.Bijection j)


-- | Some (orphan) instances that belong elsewhere (where they wouldn't be
--   orphans). Add the following line to get these instances
--   
--   <pre>
--   import Control.Instances ()
--   </pre>
module Control.Instances


-- | Various type constructor compositions and instances for them. Some
--   come from "Applicative Programming with Effects"
--   <a>http://www.soi.city.ac.uk/~ross/papers/Applicative.html</a>
module Control.Compose

-- | Unary functions
type Unop a = a -> a

-- | Binary functions
type Binop a = a -> a -> a

-- | Add post-processing
result :: Category cat => (b `cat` b') -> ((a `cat` b) -> (a `cat` b'))

-- | Add pre-processing argument :: (a' -&gt; a) -&gt; ((a -&gt; b) -&gt;
--   (a' -&gt; b))
argument :: Category cat => (a' `cat` a) -> ((a `cat` b) -> (a' `cat` b))

-- | Add pre- and post processing
(~>) :: Category cat => (a' `cat` a) -> (b `cat` b') -> ((a `cat` b) -> (a' `cat` b'))
infixr 1 ~>

-- | Like '(~&gt;)' but specialized to functors and functions.
(~>*) :: (Functor p, Functor q) => (a' -> a) -> (b -> b') -> (p a -> q b) -> (p a' -> q b')
infixr 1 ~>*
(<~) :: Category cat => (b `cat` b') -> (a' `cat` a) -> ((a `cat` b) -> (a' `cat` b'))
infixl 1 <~
(*<~) :: (Functor p, Functor q) => (b -> b') -> (a' -> a) -> (p a -> q b) -> (p a' -> q b')
infixl 1 *<~

-- | Contravariant functors. often useful for <i>acceptors</i> (consumers,
--   sinks) of values.
class ContraFunctor h
contraFmap :: ContraFunctor h => (a -> b) -> (h b -> h a)

-- | Bijections on contravariant functors
bicomap :: ContraFunctor f => (a :<->: b) -> (f a :<->: f b)

-- | Composition of unary type constructors
--   
--   There are (at least) two useful <a>Monoid</a> instances, so you'll
--   have to pick one and type-specialize it (filling in all or parts of
--   <tt>g</tt> and/or <tt>f</tt>).
--   
--   <pre>
--   -- standard Monoid instance for Applicative applied to Monoid
--   instance (Applicative (g :. f), Monoid a) =&gt; Monoid ((g :. f) a) where
--     { mempty = pure mempty; mappend = liftA2 mappend }
--   -- Especially handy when g is a Monoid_f.
--   instance Monoid (g (f a)) =&gt; Monoid ((g :. f) a) where
--     { mempty = O mempty; mappend = inO2 mappend }
--   </pre>
--   
--   Corresponding to the first and second definitions above,
--   
--   <pre>
--   instance (Applicative g, Monoid_f f) =&gt; Monoid_f (g :. f) where
--     { mempty_f = O (pure mempty_f); mappend_f = inO2 (liftA2 mappend_f) }
--   instance Monoid_f g =&gt; Monoid_f (g :. f) where
--     { mempty_f = O mempty_f; mappend_f = inO2 mappend_f }
--   </pre>
--   
--   Similarly, there are two useful <a>Functor</a> instances and two
--   useful <a>ContraFunctor</a> instances.
--   
--   <pre>
--   instance (      Functor g,       Functor f) =&gt; Functor (g :. f) where fmap = fmapFF
--   instance (ContraFunctor g, ContraFunctor f) =&gt; Functor (g :. f) where fmap = fmapCC
--   
--   instance (      Functor g, ContraFunctor f) =&gt; ContraFunctor (g :. f) where contraFmap = contraFmapFC
--   instance (ContraFunctor g,       Functor f) =&gt; ContraFunctor (g :. f) where contraFmap = contraFmapCF
--   </pre>
--   
--   However, it's such a bother to define the Functor instances per
--   composition type, I've left the fmapFF case in. If you want the fmapCC
--   one, you're out of luck for now. I'd love to hear a good solution.
--   Maybe someday Haskell will do Prolog-style search for instances,
--   subgoaling the constraints, rather than just matching instance heads.
newtype (:.) g f a
O :: (g (f a)) -> (:.) g f a

-- | Compatibility synonym
type O = (:.)

-- | Unwrap a '(:.)'.
unO :: (g :. f) a -> g (f a)

-- | <tt>newtype</tt> bijection
biO :: g (f a) :<->: (g :. f) a

-- | Compose a bijection, Functor style
convO :: Functor g => (b :<->: g c) -> (c :<->: f a) -> (b :<->: (g :. f) a)

-- | Compose a bijection, ContraFunctor style
coconvO :: ContraFunctor g => (b :<->: g c) -> (c :<->: f a) -> (b :<->: (g :. f) a)

-- | Apply a unary function within the <a>O</a> constructor.
inO :: (g (f a) -> g' (f' a')) -> ((g :. f) a -> (g' :. f') a')

-- | Apply a binary function within the <a>O</a> constructor.
inO2 :: (g (f a) -> g' (f' a') -> g'' (f'' a'')) -> ((g :. f) a -> (g' :. f') a' -> (g'' :. f'') a'')

-- | Apply a ternary function within the <a>O</a> constructor.
inO3 :: (g (f a) -> g' (f' a') -> g'' (f'' a'') -> g''' (f''' a''')) -> ((g :. f) a -> (g' :. f') a' -> (g'' :. f'') a'' -> (g''' :. f''') a''')

-- | Handy combination of <a>O</a> and <a>pure</a>.
oPure :: (Applicative g) => f a -> (g :. f) a

-- | Handy combination of <a>inO</a> and <a>fmap</a>.
oFmap :: (Functor g') => (f a -> f' a') -> (g' :. f) a -> (g' :. f') a'

-- | Handy combination of <a>inO2</a> and <a>liftA2</a>.
oLiftA2 :: (Applicative g'') => (f a -> f' a' -> f'' a'') -> (g'' :. f) a -> (g'' :. f') a' -> (g'' :. f'') a''

-- | Handy combination of <a>inO3</a> and <a>liftA3</a>.
oLiftA3 :: (Applicative g''') => (f a -> f' a' -> f'' a'' -> f''' a''') -> (g''' :. f) a -> (g''' :. f') a' -> (g''' :. f'') a'' -> (g''' :. f''') a'''

-- | Used for the <tt>Functor :. Functor</tt> instance of <a>Functor</a>
fmapFF :: (Functor g, Functor f) => (a -> b) -> (g :. f) a -> (g :. f) b

-- | Used for the <tt>ContraFunctor :. ContraFunctor</tt> instance of
--   <a>Functor</a>
fmapCC :: (ContraFunctor g, ContraFunctor f) => (a -> b) -> (g :. f) a -> (g :. f) b

-- | Used for the <tt>Functor :. ContraFunctor</tt> instance of
--   <a>Functor</a>
contraFmapFC :: (Functor g, ContraFunctor f) => (b -> a) -> (g :. f) a -> (g :. f) b

-- | Used for the <tt>ContraFunctor :. Functor</tt> instance of
--   <a>Functor</a>
contraFmapCF :: (ContraFunctor g, Functor f) => (b -> a) -> (g :. f) a -> (g :. f) b

-- | Monad distributivity.
--   
--   TODO: what conditions are required so that <tt>(m :. n)</tt> satisfies
--   the monad laws?
class DistribM m n
distribM :: DistribM m n => n (m a) -> m (n a)

-- | A candidate <a>join</a> for <tt>(m :. n)</tt>
joinDistribM :: (Monad m, Monad n, DistribM m n) => (m :. n) ((m :. n) a) -> (m :. n) a

-- | A candidate '(&gt;&gt;=)' for <tt>(m :. n)</tt>
bindDistribM :: (Functor m, Functor n, Monad m, Monad n, DistribM m n) => (m :. n) a -> (a -> (m :. n) b) -> (m :. n) b
returnDistribM :: (Monad m, Monad n) => a -> (m :. n) a

-- | <a>join</a>-like function for implicitly composed monads
joinMMT :: (Monad m, Monad n, Traversable n, Applicative m) => m (n (m (n a))) -> m (n a)

-- | <a>join</a>-like function for explicitly composed monads
joinComposeT :: (Monad m, Monad n, Traversable n, Applicative m) => (m :. n) ((m :. n) a) -> (m :. n) a

-- | Composition of type constructors: unary with binary. Called
--   <a>StaticArrow</a> in [1].
newtype OO f j a b
OO :: f (a `j` b) -> OO f j a b
[unOO] :: OO f j a b -> f (a `j` b)

-- | Common pattern for <a>Arrow</a>s.
newtype FunA h a b
FunA :: (h a -> h b) -> FunA h a b
[unFunA] :: FunA h a b -> h a -> h b

-- | Apply unary function in side a <a>FunA</a> representation.
inFunA :: ((h a -> h b) -> (h' a' -> h' b')) -> (FunA h a b -> FunA h' a' b')

-- | Apply binary function in side a <a>FunA</a> representation.
inFunA2 :: ((h a -> h b) -> (h' a' -> h' b') -> (h'' a'' -> h'' b'')) -> (FunA h a b -> FunA h' a' b' -> FunA h'' a'' b'')

-- | Support needed for a <a>FunA</a> to be an <a>Arrow</a>.
class FunAble h where f ***% g = firstFun f >>> secondFun g f &&&% g = arrFun (\ b -> (b, b)) >>> f ***% g
arrFun :: FunAble h => (a -> b) -> (h a -> h b)
firstFun :: FunAble h => (h a -> h a') -> (h (a, b) -> h (a', b))
secondFun :: FunAble h => (h b -> h b') -> (h (a, b) -> h (a, b'))
(***%) :: FunAble h => (h a -> h b) -> (h a' -> h b') -> (h (a, a') -> h (b, b'))
(&&&%) :: FunAble h => (h a -> h b) -> (h a -> h b') -> (h a -> h (b, b'))

-- | Simulates universal constraint <tt>forall a. Monoid (f a)</tt>.
--   
--   See Simulating Quantified Class Constraints
--   (<a>http://flint.cs.yale.edu/trifonov/papers/sqcc.pdf</a>) Instantiate
--   this schema wherever necessary:
--   
--   <pre>
--   instance Monoid_f f where { mempty_f = mempty ; mappend_f = mappend }
--   </pre>
class Monoid_f m
mempty_f :: forall a. Monoid_f m => m a
mappend_f :: forall a. Monoid_f m => m a -> m a -> m a

-- | Flip type arguments
newtype Flip j b a
Flip :: a `j` b -> Flip j b a
[unFlip] :: Flip j b a -> a `j` b

-- | <tt>newtype</tt> bijection
biFlip :: (a `j` b) :<->: Flip j b a
inFlip :: ((a `j` b) -> (a' `k` b')) -> (Flip j b a -> Flip k b' a')
inFlip2 :: ((a `j` b) -> (a' `k` b') -> (a'' `l` b'')) -> (Flip j b a -> Flip k b' a' -> Flip l b'' a'')
inFlip3 :: ((a `j` b) -> (a' `k` b') -> (a'' `l` b'') -> (a''' `m` b''')) -> (Flip j b a -> Flip k b' a' -> Flip l b'' a'' -> Flip m b''' a''')

-- | (-&gt; IO ()) as a <a>Flip</a>. A ContraFunctor.
type OI = Flip (->) (IO ())

-- | Convert to an <a>OI</a>.
class ToOI sink
toOI :: ToOI sink => sink b -> OI b

-- | Type application We can also drop the <tt>App</tt> constructor, but
--   then we overlap with many other instances, like <tt>[a]</tt>. Here's a
--   template for <tt>App</tt>-free instances.
--   
--   <pre>
--   instance (Applicative f, Monoid a) =&gt; Monoid (f a) where
--     mempty  = pure mempty
--     mappend = liftA2 mappend
--   </pre>
newtype (:$) f a
App :: f a -> (:$) f a
[unApp] :: (:$) f a -> f a

-- | Compatibility synonym for (:$).
type App = (:$)

-- | <tt>newtype</tt> bijection
biApp :: f a :<->: App f a
inApp :: (f a -> f' a') -> (App f a -> App f' a')
inApp2 :: (f a -> f' a' -> f'' a'') -> (App f a -> App f' a' -> App f'' a'')

-- | Identity type constructor. Until there's a better place to find it.
--   I'd use <a>Control.Monad.Identity</a>, but I don't want to introduce a
--   dependency on mtl just for Id.
newtype Id a
Id :: a -> Id a
unId :: Id a -> a

-- | <tt>newtype</tt> bijection
biId :: a :<->: Id a
inId :: (a -> b) -> (Id a -> Id b)
inId2 :: (a -> b -> c) -> (Id a -> Id b -> Id c)

-- | Pairing of unary type constructors
newtype (:*:) f g a
Prod :: (f a, g a) -> (:*:) f g a
[unProd] :: (:*:) f g a -> (f a, g a)

-- | Handy infix &amp; curried <a>Prod</a>
(*:*) :: f a -> g a -> (f :*: g) a

-- | <tt>newtype</tt> bijection
biProd :: (f a, g a) :<->: (f :*: g) a

-- | Compose a bijection
convProd :: (b :<->: f a) -> (c :<->: g a) -> (b, c) :<->: (f :*: g) a

-- | Combine two binary functions into a binary function on pairs
(***#) :: (a -> b -> c) -> (a' -> b' -> c') -> (a, a') -> (b, b') -> (c, c')
infixr 3 ***#

-- | A handy combining form. See '(***#)' for an sample use.
($*) :: (a -> b, a' -> b') -> (a, a') -> (b, b')
infixl 0 $*

-- | Apply unary function inside of <tt>f :*: g</tt> representation.
inProd :: ((f a, g a) -> (f' a', g' a')) -> ((f :*: g) a -> (f' :*: g') a')

-- | Apply binary function inside of <tt>f :*: g</tt> representation.
inProd2 :: ((f a, g a) -> (f' a', g' a') -> (f'' a'', g'' a'')) -> ((f :*: g) a -> (f' :*: g') a' -> (f'' :*: g'') a'')

-- | Apply ternary function inside of <tt>f :*: g</tt> representation.
inProd3 :: ((f a, g a) -> (f' a', g' a') -> (f'' a'', g'' a'') -> (f''' a''', g''' a''')) -> ((f :*: g) a -> (f' :*: g') a' -> (f'' :*: g'') a'' -> (f''' :*: g''') a''')

-- | Pairing of binary type constructors
newtype (::*::) f g a b
Prodd :: (f a b, g a b) -> (::*::) f g a b
[unProdd] :: (::*::) f g a b -> (f a b, g a b)

-- | Handy infix &amp; curried <a>Prodd</a>
(*::*) :: f a b -> g a b -> (f ::*:: g) a b

-- | Apply binary function inside of <tt>f :*: g</tt> representation.
inProdd :: ((f a b, g a b) -> (f' a' b', g' a' b')) -> ((f ::*:: g) a b -> (f' ::*:: g') a' b')

-- | Apply binary function inside of <tt>f :*: g</tt> representation.
inProdd2 :: ((f a b, g a b) -> (f' a' b', g' a' b') -> (f'' a'' b'', g'' a'' b'')) -> ((f ::*:: g) a b -> (f' ::*:: g') a' b' -> (f'' ::*:: g'') a'' b'')

-- | Arrow-like type between type constructors (doesn't enforce <tt>Arrow
--   (~&gt;)</tt> here).
newtype Arrw j f g a
Arrw :: f a `j` g a -> Arrw j f g a
[unArrw] :: Arrw j f g a -> f a `j` g a
type (:->:) = Arrw (->)

-- | <tt>newtype</tt> bijection
biFun :: (f a -> g a) :<->: (f :->: g) a

-- | Compose a bijection
convFun :: (b :<->: f a) -> (c :<->: g a) -> ((b -> c) :<->: (f :->: g) a)

-- | Apply unary function inside of <tt>Arrw</tt> representation.
inArrw :: ((f a `j` g a) -> (f' a' `j` g' a')) -> ((Arrw j f g) a -> (Arrw j f' g') a')

-- | Apply binary function inside of <tt>Arrw j f g</tt> representation.
inArrw2 :: ((f a `j` g a) -> (f' a' `j` g' a') -> (f'' a'' `j` g'' a'')) -> (Arrw j f g a -> Arrw j f' g' a' -> Arrw j f'' g'' a'')

-- | Apply ternary function inside of <tt>Arrw j f g</tt> representation.
inArrw3 :: ((f a `j` g a) -> (f' a' `j` g' a') -> (f'' a'' `j` g'' a'') -> (f''' a''' `j` g''' a''')) -> ((Arrw j f g) a -> (Arrw j f' g') a' -> (Arrw j f'' g'') a'' -> (Arrw j f''' g''') a''')

-- | <tt>newtype</tt> bijection
biConst :: a :<->: Const a b
inConst :: (a -> b) -> (Const a u -> Const b v)
inConst2 :: (a -> b -> c) -> Const a u -> Const b v -> Const c w
inConst3 :: (a -> b -> c -> d) -> Const a u -> Const b v -> Const c w -> Const d x

-- | <tt>newtype</tt> bijection
biEndo :: (a -> a) :<->: Endo a

-- | Convenience for partial-manipulating functions
inEndo :: (Unop a -> Unop a') -> (Endo a -> Endo a')
instance (GHC.Classes.Ord (g a b), GHC.Classes.Ord (f a b)) => GHC.Classes.Ord ((Control.Compose.::*::) f g a b)
instance (GHC.Classes.Eq (g a b), GHC.Classes.Eq (f a b)) => GHC.Classes.Eq ((Control.Compose.::*::) f g a b)
instance (GHC.Show.Show (g a b), GHC.Show.Show (f a b)) => GHC.Show.Show ((Control.Compose.::*::) f g a b)
instance GHC.Generics.Generic1 Control.Compose.Id
instance GHC.Generics.Generic (Control.Compose.Id a)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Control.Compose.Id a)
instance GHC.Show.Show a => GHC.Show.Show (Control.Compose.Id a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Control.Compose.Id a)
instance GHC.Base.Functor g => GHC.Generics.Generic1 (g Control.Compose.:. f)
instance GHC.Generics.Generic ((Control.Compose.:.) g f a)
instance GHC.Classes.Ord (g (f a)) => GHC.Classes.Ord ((Control.Compose.:.) g f a)
instance GHC.Show.Show (g (f a)) => GHC.Show.Show ((Control.Compose.:.) g f a)
instance GHC.Classes.Eq (g (f a)) => GHC.Classes.Eq ((Control.Compose.:.) g f a)
instance GHC.Base.Monoid (j (f a) (g a)) => GHC.Base.Monoid (Control.Compose.Arrw j f g a)
instance (GHC.Base.Functor g, GHC.Base.Functor f) => GHC.Base.Functor (g Control.Compose.:. f)
instance (Data.Foldable.Foldable g, Data.Foldable.Foldable f, GHC.Base.Functor g) => Data.Foldable.Foldable (g Control.Compose.:. f)
instance (Data.Traversable.Traversable g, Data.Traversable.Traversable f) => Data.Traversable.Traversable (g Control.Compose.:. f)
instance (GHC.Base.Applicative g, GHC.Base.Applicative f) => GHC.Base.Applicative (g Control.Compose.:. f)
instance (GHC.Base.Applicative f, Control.Category.Category cat) => Control.Category.Category (Control.Compose.OO f cat)
instance (GHC.Base.Applicative f, Control.Arrow.Arrow arr) => Control.Arrow.Arrow (Control.Compose.OO f arr)
instance Control.Compose.FunAble h => Control.Category.Category (Control.Compose.FunA h)
instance Control.Compose.FunAble h => Control.Arrow.Arrow (Control.Compose.FunA h)
instance Control.Compose.Monoid_f []
instance Control.Arrow.Arrow arr => Control.Compose.ContraFunctor (Control.Compose.Flip arr b)
instance (GHC.Base.Applicative (j a), GHC.Base.Monoid o) => GHC.Base.Monoid (Control.Compose.Flip j o a)
instance GHC.Base.Monoid o => Control.Compose.Monoid_f (Control.Compose.Flip (->) o)
instance Control.Compose.ToOI Control.Compose.OI
instance (GHC.Base.Applicative f, GHC.Base.Monoid m) => GHC.Base.Monoid (Control.Compose.App f m)
instance GHC.Base.Functor Control.Compose.Id
instance GHC.Base.Applicative Control.Compose.Id
instance GHC.Base.Monad Control.Compose.Id
instance Data.Foldable.Foldable Control.Compose.Id
instance Data.Traversable.Traversable Control.Compose.Id
instance GHC.Show.Show (f a, g a) => GHC.Show.Show ((Control.Compose.:*:) f g a)
instance GHC.Classes.Eq (f a, g a) => GHC.Classes.Eq ((Control.Compose.:*:) f g a)
instance GHC.Classes.Ord (f a, g a) => GHC.Classes.Ord ((Control.Compose.:*:) f g a)
instance (Control.Compose.Monoid_f f, Control.Compose.Monoid_f g) => Control.Compose.Monoid_f (f Control.Compose.:*: g)
instance (GHC.Base.Functor f, GHC.Base.Functor g) => GHC.Base.Functor (f Control.Compose.:*: g)
instance (GHC.Base.Applicative f, GHC.Base.Applicative g) => GHC.Base.Applicative (f Control.Compose.:*: g)
instance (Control.Category.Category f, Control.Category.Category f') => Control.Category.Category (f Control.Compose.::*:: f')
instance (Control.Arrow.Arrow f, Control.Arrow.Arrow f') => Control.Arrow.Arrow (f Control.Compose.::*:: f')
instance (Control.Arrow.Arrow j, Control.Compose.ContraFunctor f, GHC.Base.Functor g) => GHC.Base.Functor (Control.Compose.Arrw j f g)
instance (Control.Arrow.Arrow j, GHC.Base.Functor f, Control.Compose.ContraFunctor g) => Control.Compose.ContraFunctor (Control.Compose.Arrw j f g)
instance Control.Compose.Monoid_f Data.Monoid.Endo


-- | Some function-like classes, having lambda-like construction. See
--   <a>LambdaTy</a> for why "lambda". See <a>Data.Pair</a> for similar
--   classes.
module Data.Lambda

-- | Type of <a>lambda</a> method. Think of <tt>src</tt> as the bound
--   variable (or pattern) part of a lambda and <tt>snk</tt> as the
--   expression part. They combine to form a function-typed expression.
--   Instance template:
--   
--   <pre>
--   instance (Applicative f, Lambda src snk)
--     =&gt; Lambda (f :. src) (f :. snk) where
--       lambda = apLambda
--   </pre>
type LambdaTy src snk = forall a b. src a -> snk b -> snk (a -> b)

-- | Type constructor class for function-like things having lambda-like
--   construction.
class Lambda src snk
lambda :: Lambda src snk => LambdaTy src snk

-- | Like <tt>Unpair</tt>, but for functions. Minimal instance definition:
--   either (a) <a>unlambda</a> <i>or</i> (b) both of <a>fsrc</a>
--   <i>and</i> <a>fres</a>.
class Unlambda src snk | snk -> src where unlambda = fsrc &&& fres fsrc = fst . unlambda fres = snd . unlambda

-- | Deconstruct pair-like value
unlambda :: Unlambda src snk => snk (a -> b) -> (src a, snk b)

-- | First part of pair-like value
fsrc :: Unlambda src snk => snk (a -> b) -> src a

-- | Second part of pair-like value
fres :: Unlambda src snk => snk (a -> b) -> snk b

-- | Like <tt>Copair</tt>, but for functions
class Colambda f
cores :: Colambda f => f b -> f (a -> b)
instance Data.Lambda.Lambda Control.Compose.Id (Control.Compose.Flip (->) o)
instance Data.Lambda.Lambda GHC.Types.IO Control.Compose.OI
instance GHC.Base.Applicative f => Data.Lambda.Lambda f (f Control.Compose.:. Control.Compose.Flip (->) o)
instance GHC.Base.Applicative f => Data.Lambda.Lambda f (Control.Compose.Flip (->) o Control.Compose.:. f)
instance GHC.Base.Applicative f => Data.Lambda.Lambda f (f Control.Compose.:->: Data.Functor.Const.Const o)
instance (Data.Lambda.Lambda src snk, Data.Lambda.Lambda dom' ran') => Data.Lambda.Lambda (src Control.Compose.:*: dom') (snk Control.Compose.:*: ran')
instance (Control.Arrow.Arrow j, Data.Lambda.Unlambda f f', Data.Lambda.Lambda g g') => Data.Lambda.Lambda (Control.Compose.Arrw j f g) (Control.Compose.Arrw j f' g')
instance Data.Lambda.Unlambda Data.Monoid.Endo Data.Monoid.Endo
instance Data.Lambda.Colambda Data.Monoid.Endo


-- | Pair-related type constructor classes.
--   
--   This module is similar to <tt>Control.Functor.Pair</tt> in the
--   <tt>category-extras</tt> package, but it does not require a
--   <a>Functor</a> superclass.
--   
--   Temporarily, there is also Data.Zip, which contains the same
--   functionality with different naming. I'm unsure which I prefer.
module Data.Pair

-- | Type of <a>pair</a> method
type PairTy f = forall a b. f a -> f b -> f (a, b)

-- | Type constructor class for <a>pair</a>-like things. Here are some
--   standard instance templates you can fill in. They're not defined in
--   the general forms below, because they would lead to a lot of overlap.
--   
--   <pre>
--   instance Applicative f =&gt; Pair f where
--       pair = liftA2 (,)
--   instance (Applicative h, Pair f) =&gt; Pair (h :. f) where
--       pair = apPair
--   instance (Functor g, Pair g, Pair f) =&gt; Pair (g :. f)
--       where pair = ppPair
--   instance (Arrow (~&gt;), Unpair f, Pair g) =&gt; Pair (Arrw (~&gt;) f g) where
--       pair = arPair
--   instance (Monoid_f h, Copair h) =&gt; Pair h where
--       pair = copair
--   </pre>
--   
--   Also, if you have a type constructor that's a <a>Functor</a> and a
--   <a>Pair</a>, here is a way to define '(<a>*</a>)' for
--   <a>Applicative</a>:
--   
--   <pre>
--   (&lt;*&gt;) = pairWith ($)
--   </pre>
--   
--   Minimum definitions for instances.
class Pair f
pair :: Pair f => PairTy f

-- | Handy for <a>Pair</a> instances
apPair :: (Applicative h, Pair f) => PairTy (h :. f)

-- | Handy for <a>Pair</a> instances
ppPair :: (Functor g, Pair g, Pair f) => PairTy (g :. f)

-- | Pairing of <a>Arrw</a> values. <i>Warning</i>: definition uses
--   <a>arr</a>, so only use if your arrow has a working <a>arr</a>.
arPair :: (Arrow j, Unpair f, Pair g) => PairTy (Arrw j f g)

-- | Type of <a>unpair</a> method. Generalizes <a>unpair</a>.
type UnpairTy f = forall a b. f (a, b) -> (f a, f b)

-- | Unpairpable. Minimal instance definition: either (a) <a>unpair</a>
--   <i>or</i> (b) both of <a>fsts</a> <i>and</i> <a>snds</a>. A standard
--   template to substitute any <a>Functor</a> <tt>f.</tt> But watch out
--   for effects!
--   
--   <pre>
--   instance Functor f =&gt; Unpair f where {fsts = fmap fst; snds = fmap snd}
--   </pre>
class Unpair f where unpair = fsts &&& snds fsts = fst . unpair snds = snd . unpair
unpair :: Unpair f => UnpairTy f
fsts :: Unpair f => f (a, b) -> f a
snds :: Unpair f => f (a, b) -> f b

-- | Dual to <a>Unpair</a>. Especially handy for contravariant functors
--   (<a>ContraFunctor</a>) . Use this template (filling in <tt>f</tt>) :
--   
--   <pre>
--   instance ContraFunctor f =&gt; Copair f where
--     { cofsts = cofmap fst ; cosnds = cofmap snd }
--   </pre>
class Copair f
cofsts :: Copair f => f a -> f (a, b)
cosnds :: Copair f => f b -> f (a, b)

-- | Pairing of <a>Copair</a> values. Combines contribution of each.
copair :: (Copair f, Monoid_f f) => PairTy f

-- | Turn a pair of sources into a source of pair-editors. See
--   <a>http://conal.net/blog/posts/pairs-sums-and-reactivity/</a>.
--   'Functor'\/'Monoid' version. See also <a>pairEditM</a>.
pairEdit :: (Functor m, Monoid (m ((c, d) -> (c, d)))) => (m c, m d) -> m ((c, d) -> (c, d))

-- | Turn a pair of sources into a source of pair-editors. See
--   <a>http://conal.net/blog/posts/pairs-sums-and-reactivity/</a>. Monad
--   version. See also <a>pairEdit</a>.
pairEditM :: MonadPlus m => (m c, m d) -> m ((c, d) -> (c, d))
instance Data.Pair.Pair []
instance GHC.Base.Monoid u => Data.Pair.Pair ((,) u)
instance Data.Pair.Pair ((->) u)
instance Data.Pair.Pair GHC.Types.IO
instance GHC.Base.Monoid o => Data.Pair.Pair (Data.Functor.Const.Const o)
instance Data.Pair.Pair Control.Compose.Id
instance (Control.Arrow.Arrow j, Control.Compose.Monoid_f (Control.Compose.Flip j o)) => Data.Pair.Pair (Control.Compose.Flip j o)
instance (Control.Arrow.Arrow j, Data.Pair.Unpair f, Data.Pair.Pair g) => Data.Pair.Pair (Control.Compose.Arrw j f g)
instance (Data.Pair.Pair f, Data.Pair.Pair g) => Data.Pair.Pair (f Control.Compose.:*: g)
instance Data.Pair.Unpair []
instance Data.Pair.Unpair ((->) a)
instance Data.Pair.Unpair ((,) a)
instance Data.Pair.Unpair (Data.Functor.Const.Const a)
instance Data.Pair.Unpair Control.Compose.Id
instance Data.Pair.Copair (Data.Functor.Const.Const e)
instance Control.Arrow.Arrow j => Data.Pair.Copair (Control.Compose.Flip j o)
instance (GHC.Base.Functor h, Data.Pair.Copair f) => Data.Pair.Copair (h Control.Compose.:. f)
instance (Data.Pair.Copair f, Data.Pair.Copair g) => Data.Pair.Copair (f Control.Compose.:*: g)
instance Data.Pair.Unpair Data.Monoid.Endo
instance Data.Pair.Copair Data.Monoid.Endo
instance Data.Pair.Pair Data.Monoid.Endo


-- | Generic titling (labeling).
module Data.Title

-- | Provide a title on a value. If you can title polymorphically, please
--   instantiate <a>Title_f</a> instead of Title. Then you'll automatically
--   get a <a>Title</a> for each type instance, thanks to this rule.
--   
--   <pre>
--   instance Title_f f =&gt; Title (f a) where title = title_f
--   </pre>
--   
--   To handle ambiguity for types like <tt>([] Char)</tt> -- aka
--   <a>String</a>, this module is compiled with
--   <tt>OverlappingInstances</tt> and <tt>UndecidableInstances</tt>. The
--   more specific instance (yours) wins.
--   
--   In defining your instance, you might want to use the String instance,
--   e.g., <tt>title ttl ""</tt>.
class Title u
title :: Title u => String -> u -> u
class Title_f f

-- | <a>title</a> for all applications of <tt>f</tt>
title_f :: Title_f f => String -> f a -> f a
instance Data.Title.Title_f g => Data.Title.Title_f (g Control.Compose.:. f)
instance Data.Title.Title_f f => Data.Title.Title (f a)
instance Data.Title.Title GHC.Base.String
instance Data.Title.Title_f GHC.Types.IO
instance Data.Title.Title b => Data.Title.Title (a -> b)
instance Data.Title.Title o => Data.Title.Title_f (Control.Compose.Flip (->) o)


-- | Context-dependent monoids
module Data.CxMonoid

-- | Dictionary for <a>CxMonoid</a>.
type MonoidDict a = (a, a -> a -> a)

-- | Type of context-dependent monoid. Includes an explicit dictionary.
newtype CxMonoid a
CxMonoid :: (MonoidDict a -> a) -> CxMonoid a
[unCxMonoid] :: CxMonoid a -> MonoidDict a -> a

-- | <tt>newtype</tt> bijection
biCxMonoid :: (MonoidDict a -> a) :<->: CxMonoid a
instance GHC.Base.Monoid (Data.CxMonoid.CxMonoid a)
instance Data.Title.Title a => Data.Title.Title (Data.CxMonoid.CxMonoid a)


-- | Zip-related type constructor classes.
--   
--   This module is similar to <tt>Control.Functor.Zip</tt> in the
--   <tt>category-extras</tt> package, but it does not require a
--   <a>Functor</a> superclass.
--   
--   This module defines generalized <a>zip</a> and <a>unzip</a>, so if you
--   use it, you'll have to
--   
--   <pre>
--   import Prelude hiding (zip,zipWith,zipWith3,unzip)
--   </pre>
--   
--   Temporarily, there is also Data.Pair, which contains the same
--   functionality with different naming. I'm unsure which I prefer.
module Data.Zip

-- | Type of <a>zip</a> method
type ZipTy f = forall a b. f a -> f b -> f (a, b)

-- | Type constructor class for <a>zip</a>-like things. Here are some
--   standard instance templates you can fill in. They're not defined in
--   the general forms below, because they would lead to a lot of overlap.
--   
--   <pre>
--   instance Applicative f =&gt; Zip f where
--       zip = liftA2 (,)
--   instance (Applicative h, Zip f) =&gt; Zip (h :. f) where
--       zip = apZip
--   instance (Functor g, Zip g, Zip f) =&gt; Zip (g :. f)
--       where zip = ppZip
--   instance (Arrow (~&gt;), Unzip f, Zip g) =&gt; Zip (Arrw (~&gt;) f g) where
--       zip = arZip
--   instance (Monoid_f h, Cozip h) =&gt; Zip h where
--       zip = cozip
--   </pre>
--   
--   Also, if you have a type constructor that's a <a>Functor</a> and a
--   <a>Zip</a>, here is a way to define '(<a>*</a>)' for
--   <a>Applicative</a>:
--   
--   <pre>
--   (&lt;*&gt;) = zipWith ($)
--   </pre>
--   
--   Minimum definitions for instances.
class Zip f
zip :: Zip f => ZipTy f

-- | Generalized <a>zipWith</a>
zipWith :: (Functor f, Zip f) => (a -> b -> c) -> (f a -> f b -> f c)

-- | Generalized <a>zipWith</a>
zipWith3 :: (Functor f, Zip f) => (a -> b -> c -> d) -> (f a -> f b -> f c -> f d)

-- | Handy for <a>Zip</a> instances
apZip :: (Applicative h, Zip f) => ZipTy (h :. f)

-- | Handy for <a>Zip</a> instances
ppZip :: (Functor g, Zip g, Zip f) => ZipTy (g :. f)

-- | Ziping of <a>Arrw</a> values. <i>Warning</i>: definition uses
--   <a>arr</a>, so only use if your arrow has a working <a>arr</a>.
arZip :: (Arrow j, Unzip f, Zip g) => ZipTy (Arrw j f g)

-- | Type of <a>unzip</a> method. Generalizes <a>unzip</a>.
type UnzipTy f = forall a b. f (a, b) -> (f a, f b)

-- | Unzippable. Minimal instance definition: either (a) <a>unzip</a>
--   <i>or</i> (b) both of <a>fsts</a> <i>and</i> <a>snds</a>. A standard
--   template to substitute any <a>Functor</a> <tt>f.</tt> But watch out
--   for effects!
--   
--   <pre>
--   instance Functor f =&gt; Unzip f where {fsts = fmap fst; snds = fmap snd}
--   </pre>
class Unzip f where unzip = fsts &&& snds fsts = fst . unzip snds = snd . unzip
unzip :: Unzip f => UnzipTy f
fsts :: Unzip f => f (a, b) -> f a
snds :: Unzip f => f (a, b) -> f b

-- | Dual to <a>Unzip</a>. Especially handy for contravariant functors
--   (<tt>Cofunctor</tt>) . Use this template (filling in <tt>f</tt>) :
--   
--   <pre>
--   instance Cofunctor f =&gt; Cozip f where
--     { cofsts = cofmap fst ; cosnds = cofmap snd }
--   </pre>
class Cozip f
cofsts :: Cozip f => f a -> f (a, b)
cosnds :: Cozip f => f b -> f (a, b)

-- | Ziping of <a>Cozip</a> values. Combines contribution of each.
cozip :: (Cozip f, Monoid_f f) => ZipTy f

-- | Turn a pair of sources into a source of pair-editors. See
--   <a>http://conal.net/blog/posts/pairs-sums-and-reactivity/</a>.
--   'Functor'\/'Monoid' version. See also <a>pairEditM</a>.
pairEdit :: (Functor m, Monoid (m ((c, d) -> (c, d)))) => (m c, m d) -> m ((c, d) -> (c, d))

-- | Turn a pair of sources into a source of pair-editors. See
--   <a>http://conal.net/blog/posts/pairs-sums-and-reactivity/</a>. Monad
--   version. See also <a>pairEdit</a>.
pairEditM :: MonadPlus m => (m c, m d) -> m ((c, d) -> (c, d))
instance Data.Zip.Zip []
instance GHC.Base.Monoid u => Data.Zip.Zip ((,) u)
instance Data.Zip.Zip ((->) u)
instance Data.Zip.Zip GHC.Types.IO
instance GHC.Base.Monoid o => Data.Zip.Zip (Data.Functor.Const.Const o)
instance Data.Zip.Zip Control.Compose.Id
instance (Control.Arrow.Arrow j, Control.Compose.Monoid_f (Control.Compose.Flip j o)) => Data.Zip.Zip (Control.Compose.Flip j o)
instance (Control.Arrow.Arrow j, Data.Zip.Unzip f, Data.Zip.Zip g) => Data.Zip.Zip (Control.Compose.Arrw j f g)
instance (Data.Zip.Zip f, Data.Zip.Zip g) => Data.Zip.Zip (f Control.Compose.:*: g)
instance Data.Zip.Unzip []
instance Data.Zip.Unzip ((->) a)
instance Data.Zip.Unzip ((,) a)
instance Data.Zip.Unzip (Data.Functor.Const.Const a)
instance Data.Zip.Unzip Control.Compose.Id
instance Data.Zip.Cozip (Data.Functor.Const.Const e)
instance Control.Arrow.Arrow j => Data.Zip.Cozip (Control.Compose.Flip j o)
instance (GHC.Base.Functor h, Data.Zip.Cozip f) => Data.Zip.Cozip (h Control.Compose.:. f)
instance (Data.Zip.Cozip f, Data.Zip.Cozip g) => Data.Zip.Cozip (f Control.Compose.:*: g)
instance Data.Zip.Unzip Data.Monoid.Endo
instance Data.Zip.Cozip Data.Monoid.Endo
instance Data.Zip.Zip Data.Monoid.Endo


-- | A monoid <a>Partial</a> of partial values. See the [Teaser] and
--   [Solution] blog posts.
--   
--   <ul>
--   <li><i>Teaser</i>
--   <a>http://conal.net/blog/posts/a-type-for-partial-values</a></li>
--   <li><i>Solution</i>
--   <a>http://conal.net/blog/posts/implementing-a-type-for-partial-values</a></li>
--   </ul>
--   
--   Also defines a <a>FunAble</a> instance, so that <tt>FunA Partial</tt>
--   is an arrow.
module Data.Partial

-- | Partial value. Represented an endomorphism, which is a <a>Monoid</a>
--   under <a>id</a> and '(.)'. Then <a>mempty</a> is the completely
--   undefined value, and in <tt>u `</tt>'mappend'@` v<tt>, </tt>v<tt>
--   selectively replaces parts of </tt>u@. The <a>Endo</a> instances for
--   <tt>Pair</tt>, <tt>Unpair</tt>, <tt>Copair</tt>, <tt>Unfun</tt>, and
--   <tt>Cofun</tt> are all very useful on partial values.
type Partial = Endo
type PartialX a b = Partial a -> Partial b

-- | Treat a full value as a partial one. Fully overrides any "previous"
--   (earlier argument to <tt>mappend</tt>) partial value.
valp :: c -> Partial c

-- | Force a partial value into a full one, filling in bottom for any
--   missing parts.
pval :: Partial c -> c

-- | Inverse to "element" access, on all elements. A way to inject some
--   info about every element. For <tt>f</tt>, consider '[]', <tt>(-&gt;)
--   a</tt>, <tt>Event</tt>, etc.
pUnElt :: Functor f => PartialX a (f a)

-- | Provide in info about a function argument
pUnArg :: PartialX u (u -> v)

-- | Provide info about a function result
pUnRes :: PartialX v (u -> v)

-- | Inject a partial argument-source into a partial function-sink.
pUnSrc :: PartialX a ((a -> b) -> o)
instance Control.Compose.FunAble Data.Partial.Partial
