-- 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 -- -- © 2007-2010 by Conal Elliott; BSD3 license. @package TypeCompose @version 0.8.3 -- | 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 instance Monoid o => Monoid (IO o) -- | 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 RefMonad (ST s) (STRef s) instance RefMonad IO IORef -- | 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 ~> a b Bi :: a ~> b -> b ~> a -> Bijection ~> a b biTo :: Bijection ~> a b -> a ~> b biFrom :: Bijection ~> a b -> b ~> 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 ~> => Bijection ~> a a -- | Inverse bijection inverse :: Bijection ~> a b -> Bijection ~> b a -- | Bijections on functors bimap :: Functor f => (a :<->: b) -> (f a :<->: f b) -- | Bijections on arrows. (--->) :: Arrow ~> => Bijection ~> a b -> Bijection ~> c d -> (a ~> c) :<->: (b ~> d) -- | Apply a function in an alternative (monomorphic) representation. inBi :: Arrow ~> => Bijection ~> a b -> (a ~> a) -> (b ~> b) instance Arrow (~>) => Arrow (Bijection (~>)) instance Category (~>) => Category (Bijection (~>)) -- | 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 :: (b -> b') -> ((a -> b) -> (a -> b')) -- | Add pre-processing argument :: (a' -> a) -> ((a -> b) -> (a' -> b)) -- | Add pre- and post processing (~>) :: Category --> => (a' --> a) -> (b --> b') -> ((a --> b) -> (a' --> b')) -- | Like '(~>)' but specialized to functors (~>*) :: Functor f => (a' -> a) -> (b -> b') -> (f a -> f b) -> (f a' -> f b') -- | Contravariant functors. often useful for acceptors (consumers, -- sinks) of values. class Cofunctor acc cofmap :: Cofunctor acc => (a -> b) -> (acc b -> acc a) -- | Bijections on contravariant functors bicomap :: Cofunctor 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 Cofunctor instances.
--
-- -- instance ( Functor g, Functor f) => Functor (g :. f) where fmap = fmapFF -- instance (Cofunctor g, Cofunctor f) => Functor (g :. f) where fmap = fmapCC -- -- instance (Functor g, Cofunctor f) => Cofunctor (g :. f) where cofmap = cofmapFC -- instance (Cofunctor g, Functor f) => Cofunctor (g :. f) where cofmap = cofmapCF ---- -- 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, Cofunctor style coconvO :: Cofunctor 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 Cofunctor :. Cofunctor instance of -- Functor fmapCC :: (Cofunctor g, Cofunctor f) => (a -> b) -> (g :. f) a -> (g :. f) b -- | Used for the Functor :. Cofunctor instance of Functor cofmapFC :: (Functor g, Cofunctor f) => (b -> a) -> (g :. f) a -> (g :. f) b -- | Used for the Cofunctor :. Functor instance of Functor cofmapCF :: (Cofunctor g, Functor f) => (b -> a) -> (g :. f) a -> (g :. f) b -- | Composition of type constructors: unary with binary. Called -- StaticArrow in [1]. newtype OO f ~> a b OO :: f (a ~> b) -> OO f ~> a b unOO :: OO f ~> a b -> f (a ~> 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 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 ~> b a
Flip :: a ~> b -> Flip ~> b a
unFlip :: Flip ~> b a -> a ~> b
-- | newtype bijection
biFlip :: (a ~> b) :<->: Flip ~> b a
inFlip :: ((a ~> b) -> (a' ~~> b')) -> (Flip ~> b a -> Flip ~~> b' a')
inFlip2 :: ((a ~> b) -> (a' ~~> b') -> (a'' ~~~> b'')) -> (Flip ~> b a -> Flip ~~> b' a' -> Flip ~~~> b'' a'')
inFlip3 :: ((a ~> b) -> (a' ~~> b') -> (a'' ~~~> b'') -> (a''' ~~~~> b''')) -> (Flip ~> b a -> Flip ~~> b' a' -> Flip ~~~> b'' a'' -> Flip ~~~~> b''' a''')
-- | (-> IO ()) as a Flip. A Cofunctor.
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) -- | 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) -- | 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 ~> f g a Arrw :: f a ~> g a -> Arrw ~> f g a unArrw :: Arrw ~> f g a -> f a ~> 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 ~> g a) -> (f' a' ~> g' a')) -> ((Arrw ~> f g) a -> (Arrw ~> f' g') a') -- | Apply binary function inside of Arrw (~>) f g -- representation. inArrw2 :: ((f a ~> g a) -> (f' a' ~> g' a') -> (f'' a'' ~> g'' a'')) -> (Arrw ~> f g a -> Arrw ~> f' g' a' -> Arrw ~> f'' g'' a'') -- | Apply ternary function inside of Arrw (~>) f g -- representation. inArrw3 :: ((f a ~> g a) -> (f' a' ~> g' a') -> (f'' a'' ~> g'' a'') -> (f''' a''' ~> g''' a''')) -> ((Arrw ~> f g) a -> (Arrw ~> f' g') a' -> (Arrw ~> f'' g'') a'' -> (Arrw ~> 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 Monoid ((~>) (f a) (g a)) => Monoid (Arrw (~>) f g a) instance Show (g (f a)) => Show ((:.) g f a) instance Show a => Show (Id a) instance (Show (f a b), Show (g a b)) => Show ((::*::) f g a b) instance (Eq (f a b), Eq (g a b)) => Eq ((::*::) f g a b) instance (Ord (f a b), Ord (g a b)) => Ord ((::*::) f g a b) instance Monoid_f Endo instance Monoid o => Monoid (Const o a) instance (Arrow (~>), Functor f, Cofunctor g) => Cofunctor (Arrw (~>) f g) instance (Arrow (~>), Cofunctor f, Functor g) => Functor (Arrw (~>) f g) instance (Arrow f, Arrow f') => Arrow (f ::*:: f') instance (Category f, Category f') => Category (f ::*:: f') instance (Applicative f, Applicative g) => Applicative (f :*: g) instance (Functor f, Functor g) => Functor (f :*: g) instance (Monoid_f f, Monoid_f g) => Monoid_f (f :*: g) instance Ord (f a, g a) => Ord ((:*:) f g a) instance Eq (f a, g a) => Eq ((:*:) f g a) instance Show (f a, g a) => Show ((:*:) f g a) instance Applicative Id instance Functor Id instance (Applicative f, Monoid m) => Monoid (App f m) instance ToOI OI instance Monoid o => Monoid_f (Flip (->) o) instance (Applicative ((~>) a), Monoid o) => Monoid (Flip (~>) o a) instance Arrow (~>) => Cofunctor (Flip (~>) b) instance Monoid_f [] instance FunAble h => Arrow (FunA h) instance FunAble h => Category (FunA h) instance (Applicative f, Arrow (~>)) => Arrow (OO f (~>)) instance (Applicative f, Category (~>)) => Category (OO f (~>)) instance (Applicative g, Applicative f) => Applicative (g :. f) instance (Traversable g, Traversable f) => Traversable (g :. f) instance (Foldable g, Foldable f, Functor g) => Foldable (g :. f) instance (Functor g, Functor f) => Functor (g :. f) -- | 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_f :: Title_f f => String -> f a -> f a instance [overlap ok] Title o => Title_f (Flip (->) o) instance [overlap ok] Title b => Title (a -> b) instance [overlap ok] Title_f IO instance [overlap ok] Title String instance [overlap ok] Title_f f => Title (f a) instance [overlap ok] Title_f g => Title_f (g :. f) -- | 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 Title a => Title (CxMonoid a) instance Monoid (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 ~>, Unpair f, Pair g) => PairTy (Arrw ~> 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
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
-- (Cofunctor) . Use this template (filling in f) :
--
--
-- instance Cofunctor 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 Pair Endo
instance Copair Endo
instance Unpair Endo
instance (Copair f, Copair g) => Copair (f :*: g)
instance (Functor h, Copair f) => Copair (h :. f)
instance Arrow (~>) => Copair (Flip (~>) o)
instance Copair (Const e)
instance Unpair Id
instance Unpair (Const a)
instance Unpair ((,) a)
instance Unpair ((->) a)
instance Unpair []
instance (Pair f, Pair g) => Pair (f :*: g)
instance (Arrow (~>), Unpair f, Pair g) => Pair (Arrw (~>) f g)
instance (Arrow (~>), Monoid_f (Flip (~>) o)) => Pair (Flip (~>) o)
instance Pair Id
instance Monoid o => Pair (Const o)
instance Pair IO
instance Pair ((->) u)
instance Monoid u => Pair ((,) u)
instance Pair []
-- | 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 ~>, Unzip f, Zip g) => ZipTy (Arrw ~> 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
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 Zip Endo
instance Cozip Endo
instance Unzip Endo
instance (Cozip f, Cozip g) => Cozip (f :*: g)
instance (Functor h, Cozip f) => Cozip (h :. f)
instance Arrow (~>) => Cozip (Flip (~>) o)
instance Cozip (Const e)
instance Unzip Id
instance Unzip (Const a)
instance Unzip ((,) a)
instance Unzip ((->) a)
instance Unzip []
instance (Zip f, Zip g) => Zip (f :*: g)
instance (Arrow (~>), Unzip f, Zip g) => Zip (Arrw (~>) f g)
instance (Arrow (~>), Monoid_f (Flip (~>) o)) => Zip (Flip (~>) o)
instance Zip Id
instance Monoid o => Zip (Const o)
instance Zip IO
instance Zip ((->) u)
instance Monoid u => Zip ((,) u)
instance Zip []
-- | 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 unlambda :: Unlambda src snk => snk (a -> b) -> (src a, snk b) fsrc :: Unlambda src snk => snk (a -> b) -> src a 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 Colambda Endo instance Unlambda Endo Endo instance (Arrow (~>), Unlambda f f', Lambda g g') => Lambda (Arrw (~>) f g) (Arrw (~>) f' g') instance (Lambda src snk, Lambda dom' ran') => Lambda (src :*: dom') (snk :*: ran') instance Applicative f => Lambda f (f :->: Const o) instance Applicative f => Lambda f (Flip (->) o :. f) instance Applicative f => Lambda f (f :. Flip (->) o) instance Lambda IO OI instance Lambda Id (Flip (->) o)