-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Type composition classes & instances -- -- TypeCompose provides some classes & instances for forms of type -- composition, as well as some modules who haven't yet found a home. -- -- Please see the project wiki page: -- http://haskell.org/haskellwiki/TypeCompose -- -- Copyright 2007-2012 by Conal Elliott; BSD3 license. @package TypeCompose @version 0.9.11 -- | Some (orphan) instances that belong elsewhere (where they wouldn't be -- orphans). Add the following line to get these instances -- --
-- import Control.Instances () --module Control.Instances -- | Monads with references, taken from John Hughes's "Global Variables in -- Haskell" (http://citeseer.ist.psu.edu/473734.html). 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] There and Back -- Again: Arrows for Invertible Programming, -- http://citeseer.ist.psu.edu/alimarine05there.html. 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 arr on -- (~>). If you have no arr, but you have a -- DeepArrow, you can instead use Bi idA idA. 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) -- | 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) -- | Various type constructor compositions and instances for them. Some -- come from "Applicative Programming with Effects" -- http://www.soi.city.ac.uk/~ross/papers/Applicative.html 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' -> a) -> ((a -> b) -> -- (a' -> 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')) -- | Like '(~>)' but specialized to functors and functions. (~>*) :: (Functor p, Functor q) => (a' -> a) -> (b -> b') -> (p a -> q b) -> (p a' -> q b') (<~) :: Category cat => (b `cat` b') -> (a' `cat` a) -> ((a `cat` b) -> (a' `cat` b')) (*<~) :: (Functor p, Functor q) => (b -> b') -> (a' -> a) -> (p a -> q b) -> (p a' -> q b') -- | Contravariant functors. often useful for acceptors (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 Monoid instances, so you'll -- have to pick one and type-specialize it (filling in all or parts of -- g and/or f). -- --
-- -- standard Monoid instance for Applicative applied to Monoid
-- instance (Applicative (g :. f), Monoid a) => Monoid ((g :. f) a) where
-- { mempty = pure mempty; mappend = liftA2 mappend }
-- -- Especially handy when g is a Monoid_f.
-- instance Monoid (g (f a)) => Monoid ((g :. f) a) where
-- { mempty = O mempty; mappend = inO2 mappend }
--
--
-- Corresponding to the first and second definitions above,
--
--
-- instance (Applicative g, Monoid_f f) => Monoid_f (g :. f) where
-- { mempty_f = O (pure mempty_f); mappend_f = inO2 (liftA2 mappend_f) }
-- instance Monoid_f g => Monoid_f (g :. f) where
-- { mempty_f = O mempty_f; mappend_f = inO2 mappend_f }
--
--
-- Similarly, there are two useful Functor instances and two
-- useful ContraFunctor instances.
--
-- -- instance ( Functor g, Functor f) => Functor (g :. f) where fmap = fmapFF -- instance (ContraFunctor g, ContraFunctor f) => Functor (g :. f) where fmap = fmapCC -- -- instance ( Functor g, ContraFunctor f) => ContraFunctor (g :. f) where contraFmap = contraFmapFC -- instance (ContraFunctor g, Functor f) => ContraFunctor (g :. f) where contraFmap = contraFmapCF ---- -- 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) -- | newtype 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 O constructor. inO :: (g (f a) -> g' (f' a')) -> ((g :. f) a -> (g' :. f') a') -- | Apply a binary function within the O 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 O 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 O and pure. oPure :: (Applicative g) => f a -> (g :. f) a -- | Handy combination of inO and fmap. oFmap :: (Functor g') => (f a -> f' a') -> (g' :. f) a -> (g' :. f') a' -- | Handy combination of inO2 and liftA2. oLiftA2 :: (Applicative g'') => (f a -> f' a' -> f'' a'') -> (g'' :. f) a -> (g'' :. f') a' -> (g'' :. f'') a'' -- | Handy combination of inO3 and liftA3. 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 Functor :. Functor instance of Functor fmapFF :: (Functor g, Functor f) => (a -> b) -> (g :. f) a -> (g :. f) b -- | Used for the ContraFunctor :. ContraFunctor instance of -- Functor fmapCC :: (ContraFunctor g, ContraFunctor f) => (a -> b) -> (g :. f) a -> (g :. f) b -- | Used for the Functor :. ContraFunctor instance of -- Functor contraFmapFC :: (Functor g, ContraFunctor f) => (b -> a) -> (g :. f) a -> (g :. f) b -- | Used for the ContraFunctor :. Functor instance of -- Functor contraFmapCF :: (ContraFunctor g, Functor f) => (b -> a) -> (g :. f) a -> (g :. f) b -- | Monad distributivity. -- -- TODO: what conditions are required so that (m :. n) satisfies -- the monad laws? class DistribM m n distribM :: DistribM m n => n (m a) -> m (n a) -- | A candidate join for (m :. n) joinDistribM :: (Monad m, Monad n, DistribM m n) => (m :. n) ((m :. n) a) -> (m :. n) a -- | A candidate '(>>=)' for (m :. n) 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 -- | join-like function for implicitly composed monads joinMMT :: (Monad m, Monad n, Traversable n, Applicative m) => m (n (m (n a))) -> m (n a) -- | join-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 -- StaticArrow 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 Arrows. 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 FunA representation. inFunA :: ((h a -> h b) -> (h' a' -> h' b')) -> (FunA h a b -> FunA h' a' b') -- | Apply binary function in side a FunA 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 FunA to be an Arrow. 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 forall a. Monoid (f a). -- -- See Simulating Quantified Class Constraints -- (http://flint.cs.yale.edu/trifonov/papers/sqcc.pdf) Instantiate -- this schema wherever necessary: -- --
-- instance Monoid_f f where { mempty_f = mempty ; mappend_f = mappend }
--
class Monoid_f m
mempty_f :: Monoid_f m => m a
mappend_f :: 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
-- | newtype 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''')
-- | (-> IO ()) as a Flip. A ContraFunctor.
type OI = Flip (->) (IO ())
-- | Convert to an OI.
class ToOI sink
toOI :: ToOI sink => sink b -> OI b
-- | Type application We can also drop the App constructor, but
-- then we overlap with many other instances, like [a]. Here's a
-- template for App-free instances.
--
-- -- instance (Applicative f, Monoid a) => Monoid (f a) where -- mempty = pure mempty -- mappend = liftA2 mappend --newtype (:$) f a App :: f a -> (:$) f a [unApp] :: (:$) f a -> f a -- | Compatibility synonym for (:$). type App = (:$) -- | newtype 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 Control.Monad.Identity, 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 -- | newtype 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 & curried Prod (*:*) :: f a -> g a -> (f :*: g) a -- | newtype 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') -- | A handy combining form. See '(***#)' for an sample use. ($*) :: (a -> b, a' -> b') -> (a, a') -> (b, b') -- | Apply unary function inside of f :*: g representation. inProd :: ((f a, g a) -> (f' a', g' a')) -> ((f :*: g) a -> (f' :*: g') a') -- | Apply binary function inside of f :*: g 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 f :*: g 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 & curried Prodd (*::*) :: f a b -> g a b -> (f ::*:: g) a b -- | Apply binary function inside of f :*: g 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 f :*: g 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 Arrow -- (~>) 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 (->) -- | newtype 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 Arrw 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 Arrw j f g 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 Arrw j f g 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''') -- | newtype 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 -- | newtype bijection biEndo :: (a -> a) :<->: Endo a -- | Convenience for partial-manipulating functions inEndo :: (Unop a -> Unop a') -> (Endo a -> Endo a') instance (GHC.Classes.Ord (f a b), GHC.Classes.Ord (g a b)) => GHC.Classes.Ord ((Control.Compose.::*::) f g a b) instance (GHC.Classes.Eq (f a b), GHC.Classes.Eq (g a b)) => GHC.Classes.Eq ((Control.Compose.::*::) f g a b) instance (GHC.Show.Show (f a b), GHC.Show.Show (g a b)) => GHC.Show.Show ((Control.Compose.::*::) f g a b) instance GHC.Show.Show a => GHC.Show.Show (Control.Compose.Id 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 -- | Generic titling (labeling). module Data.Title -- | Provide a title on a value. If you can title polymorphically, please -- instantiate Title_f instead of Title. Then you'll automatically -- get a Title for each type instance, thanks to this rule. -- --
-- instance Title_f f => Title (f a) where title = title_f ---- -- To handle ambiguity for types like ([] Char) -- aka -- String, this module is compiled with -- OverlappingInstances and UndecidableInstances. The -- more specific instance (yours) wins. -- -- In defining your instance, you might want to use the String instance, -- e.g., title ttl "". class Title u title :: Title u => String -> u -> u class Title_f f -- | title for all applications of f 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 CxMonoid. 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 -- | newtype 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) -- | Pair-related type constructor classes. -- -- This module is similar to Control.Functor.Pair in the -- category-extras package, but it does not require a -- Functor 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 pair method type PairTy f = forall a b. f a -> f b -> f (a, b) -- | Type constructor class for pair-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. -- --
-- instance Applicative f => Pair f where -- pair = liftA2 (,) -- instance (Applicative h, Pair f) => Pair (h :. f) where -- pair = apPair -- instance (Functor g, Pair g, Pair f) => Pair (g :. f) -- where pair = ppPair -- instance (Arrow (~>), Unpair f, Pair g) => Pair (Arrw (~>) f g) where -- pair = arPair -- instance (Monoid_f h, Copair h) => Pair h where -- pair = copair ---- -- Also, if you have a type constructor that's a Functor and a -- Pair, here is a way to define '(*)' for -- Applicative: -- --
-- (<*>) = pairWith ($) ---- -- Minimum definitions for instances. class Pair f pair :: Pair f => PairTy f -- | Handy for Pair instances apPair :: (Applicative h, Pair f) => PairTy (h :. f) -- | Handy for Pair instances ppPair :: (Functor g, Pair g, Pair f) => PairTy (g :. f) -- | Pairing of Arrw values. Warning: definition uses -- arr, so only use if your arrow has a working arr. arPair :: (Arrow j, Unpair f, Pair g) => PairTy (Arrw j f g) -- | Type of unpair method. Generalizes unpair. type UnpairTy f = forall a b. f (a, b) -> (f a, f b) -- | Unpairpable. Minimal instance definition: either (a) unpair -- or (b) both of fsts and snds. A standard -- template to substitute any Functor f. But watch out -- for effects! -- --
-- instance Functor f => Unpair f where {fsts = fmap fst; snds = fmap snd}
--
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 Unpair. Especially handy for contravariant functors
-- (ContraFunctor) . Use this template (filling in f) :
--
--
-- instance ContraFunctor f => Copair f where
-- { cofsts = cofmap fst ; cosnds = cofmap snd }
--
class Copair f
cofsts :: Copair f => f a -> f (a, b)
cosnds :: Copair f => f b -> f (a, b)
-- | Pairing of Copair 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
-- http://conal.net/blog/posts/pairs-sums-and-reactivity/.
-- 'Functor'\/'Monoid' version. See also pairEditM.
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
-- http://conal.net/blog/posts/pairs-sums-and-reactivity/. Monad
-- version. See also pairEdit.
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 (Control.Applicative.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 (Control.Applicative.Const a)
instance Data.Pair.Unpair Control.Compose.Id
instance Data.Pair.Copair (Control.Applicative.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
-- | Zip-related type constructor classes.
--
-- This module is similar to Control.Functor.Zip in the
-- category-extras package, but it does not require a
-- Functor superclass.
--
-- This module defines generalized zip and unzip, so if you
-- use it, you'll have to
--
-- -- import Prelude hiding (zip,zipWith,zipWith3,unzip) ---- -- 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 zip method type ZipTy f = forall a b. f a -> f b -> f (a, b) -- | Type constructor class for zip-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. -- --
-- instance Applicative f => Zip f where -- zip = liftA2 (,) -- instance (Applicative h, Zip f) => Zip (h :. f) where -- zip = apZip -- instance (Functor g, Zip g, Zip f) => Zip (g :. f) -- where zip = ppZip -- instance (Arrow (~>), Unzip f, Zip g) => Zip (Arrw (~>) f g) where -- zip = arZip -- instance (Monoid_f h, Cozip h) => Zip h where -- zip = cozip ---- -- Also, if you have a type constructor that's a Functor and a -- Zip, here is a way to define '(*)' for -- Applicative: -- --
-- (<*>) = zipWith ($) ---- -- Minimum definitions for instances. class Zip f zip :: Zip f => ZipTy f -- | Generalized zipWith zipWith :: (Functor f, Zip f) => (a -> b -> c) -> (f a -> f b -> f c) -- | Generalized zipWith zipWith3 :: (Functor f, Zip f) => (a -> b -> c -> d) -> (f a -> f b -> f c -> f d) -- | Handy for Zip instances apZip :: (Applicative h, Zip f) => ZipTy (h :. f) -- | Handy for Zip instances ppZip :: (Functor g, Zip g, Zip f) => ZipTy (g :. f) -- | Ziping of Arrw values. Warning: definition uses -- arr, so only use if your arrow has a working arr. arZip :: (Arrow j, Unzip f, Zip g) => ZipTy (Arrw j f g) -- | Type of unzip method. Generalizes unzip. type UnzipTy f = forall a b. f (a, b) -> (f a, f b) -- | Unzippable. Minimal instance definition: either (a) unzip -- or (b) both of fsts and snds. A standard -- template to substitute any Functor f. But watch out -- for effects! -- --
-- instance Functor f => Unzip f where {fsts = fmap fst; snds = fmap snd}
--
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 Unzip. Especially handy for contravariant functors
-- (Cofunctor) . Use this template (filling in f) :
--
--
-- instance Cofunctor f => Cozip f where
-- { cofsts = cofmap fst ; cosnds = cofmap snd }
--
class Cozip f
cofsts :: Cozip f => f a -> f (a, b)
cosnds :: Cozip f => f b -> f (a, b)
-- | Ziping of Cozip 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
-- http://conal.net/blog/posts/pairs-sums-and-reactivity/.
-- 'Functor'\/'Monoid' version. See also pairEditM.
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
-- http://conal.net/blog/posts/pairs-sums-and-reactivity/. Monad
-- version. See also pairEdit.
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 (Control.Applicative.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 (Control.Applicative.Const a)
instance Data.Zip.Unzip Control.Compose.Id
instance Data.Zip.Cozip (Control.Applicative.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 Partial of partial values. See the [Teaser] and
-- [Solution] blog posts.
--
-- -- instance (Applicative f, Lambda src snk) -- => Lambda (f :. src) (f :. snk) where -- lambda = apLambda --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 Unpair, but for functions. Minimal instance definition: -- either (a) unlambda or (b) both of fsrc -- and fres. 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 Copair, 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.:->: Control.Applicative.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