-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | The double category of Hask functors and profunctors -- -- A library for working with natural transformations of type -- --
-- forall a b. p a b -> q (f a) (g b) --@package squares @version 0.1 -- | Utilities for type level lists. module Data.Type.List -- | Type level list append type family (as :: [k]) ++ (bs :: [k]) :: [k] module Data.Profunctor.Composition.List -- | N-ary composition of profunctors. data PList (ps :: [* -> * -> *]) (a :: *) (b :: *) [Hom] :: {unHom :: a -> b} -> PList '[] a b [P] :: {unP :: p a b} -> PList '[p] a b [PComp] :: p a x -> PList (q : qs) x b -> PList (p : (q : qs)) a b -- | Calculate the simplified type of the composition of a list of -- profunctors. type family PlainP (ps :: [* -> * -> *]) :: * -> * -> * -- | Functions for working with PLists. class IsPList ps -- | Combine 2 nested PLists into one PList. pappend :: (IsPList ps, Profunctor (PList qs)) => Procompose (PList qs) (PList ps) :-> PList (ps ++ qs) -- | Split one PList into 2 nested PLists. punappend :: IsPList ps => PList (ps ++ qs) :-> Procompose (PList qs) (PList ps) -- | Convert a PList to its simplified form. toPlainP :: IsPList ps => PList ps :-> PlainP ps -- | Create a PList from its simplified form. fromPlainP :: IsPList ps => PlainP ps :-> PList ps instance Data.Profunctor.Composition.List.IsPList '[] instance Data.Profunctor.Unsafe.Profunctor p => Data.Profunctor.Composition.List.IsPList '[p] instance Data.Profunctor.Composition.List.IsPList (q : qs) => Data.Profunctor.Composition.List.IsPList (p : q : qs) instance Data.Profunctor.Unsafe.Profunctor (Data.Profunctor.Composition.List.PList '[]) instance Data.Profunctor.Unsafe.Profunctor p => Data.Profunctor.Unsafe.Profunctor (Data.Profunctor.Composition.List.PList '[p]) instance (Data.Profunctor.Unsafe.Profunctor p, Data.Profunctor.Unsafe.Profunctor (Data.Profunctor.Composition.List.PList (q : qs))) => Data.Profunctor.Unsafe.Profunctor (Data.Profunctor.Composition.List.PList (p : q : qs)) module Data.Functor.Compose.List -- | N-ary composition of functors. -- --
-- FList '[] a ~ a -- FList '[f, g, h] a ~ h (g (f a)) --data FList (fs :: [* -> *]) (a :: *) [Id] :: {unId :: a} -> FList '[] a [F] :: {unF :: f a} -> FList '[f] a [FComp] :: {unFComp :: FList (g : gs) (f a)} -> FList (f : (g : gs)) a -- | Calculate the simplified type of the composition of a list of -- functors. type family PlainF (fs :: [* -> *]) (a :: *) :: * -- | Functions for working with FLists. class IsFList fs -- | Combine 2 nested FLists into one FList. fappend :: (IsFList fs, Functor (FList gs)) => FList gs (FList fs a) -> FList (fs ++ gs) a -- | Split one FList into 2 nested FLists. funappend :: (IsFList fs, Functor (FList gs)) => FList (fs ++ gs) a -> FList gs (FList fs a) -- | Convert an FList to its simplified form. toPlainF :: IsFList fs => FList fs a -> PlainF fs a -- | Create an FList from its simplified form. fromPlainF :: IsFList fs => PlainF fs a -> FList fs a -- | Natural transformations between two functors. (Why is this still not -- in base??) type f ~> g = forall a. f a -> g a instance Data.Functor.Compose.List.IsFList '[] instance Data.Functor.Compose.List.IsFList '[f] instance Data.Functor.Compose.List.IsFList (g : gs) => Data.Functor.Compose.List.IsFList (f : g : gs) instance GHC.Base.Functor (Data.Functor.Compose.List.FList '[]) instance GHC.Base.Functor f => GHC.Base.Functor (Data.Functor.Compose.List.FList '[f]) instance (GHC.Base.Functor f, GHC.Base.Functor (Data.Functor.Compose.List.FList (g : gs))) => GHC.Base.Functor (Data.Functor.Compose.List.FList (f : g : gs)) module Data.Square -- |
-- +-----+ -- | | -- | | -- | | -- +-----+ ---- --
-- forall a b. (a -> b) -> (a -> b) ---- -- The empty square is the identity transformation. emptySquare :: Square '[] '[] '[] '[] -- |
-- +-----+ -- | | -- p-----p -- | | -- +-----+ ---- --
-- forall a b. p a b -> p a b ---- -- Profunctors are drawn as horizontal lines. -- -- Note that emptySquare is proId for the profunctor -- (->). We don't draw a line for (->) because it -- is the identity for profunctor composition. proId :: Profunctor p => Square '[p] '[p] '[] '[] -- |
-- +--f--+ -- | | | -- | v | -- | | | -- +--f--+ ---- --
-- forall a b. (a -> b) -> (f a -> f b) ---- -- Functors are drawn with vertical lines with arrow heads. You will -- recognize the above type as fmap! -- -- We don't draw lines for the identity functor, because it is the -- identity for functor composition. funId :: Functor f => Square '[] '[] '[f] '[f] -- |
-- +--f--+ -- | | | -- | @ | -- | | | -- +--g--+ ---- --
-- forall a b. (a -> b) -> (f a -> g b) ---- -- Non-identity transformations are drawn with an @ in the -- middle. Natural transformations between haskell functors are usualy -- given the type forall a. f a -> g a. The type above you -- get when fmapping before or after. (It doesn't matter which, -- because of naturality!) funNat :: (Functor f, Functor g) => (f ~> g) -> Square '[] '[] '[f] '[g] -- |
-- +-----+ -- | | -- p--@--q -- | | -- +-----+ ---- --
-- forall a b. p a b -> q a b ---- -- Natural transformations between profunctors. proNat :: (Profunctor p, Profunctor q) => (p :-> q) -> Square '[p] '[q] '[] '[] -- |
-- +--f--+ -- | v | -- p--@--q -- | v | -- +--g--+ ---- --
-- forall a b. p a b -> q (f a) (g b) ---- -- The complete definition of a square is a combination of natural -- transformations between functors and natural transformations between -- profunctors. -- -- To make type inferencing easier the above type is wrapped by a -- newtype. newtype SquareNT p q f g Square :: (forall a b. p a b -> q (f a) (g b)) -> SquareNT p q f g [unSquare] :: SquareNT p q f g -> forall a b. p a b -> q (f a) (g b) -- | To make composing squares associative, this library uses squares with -- lists of functors and profunctors, which are composed together. -- --
-- FList '[] a ~ a -- FList '[f, g, h] a ~ h (g (f a)) -- PList '[] a b ~ a -> b -- PList '[p, q, r] a b ~ (p a x, q x y, r y b) --type Square ps qs fs gs = SquareNT (PList ps) (PList qs) (FList fs) (FList gs) -- | A helper function to add the wrappers needed for PList and -- FList. mkSquare :: (IsPList ps, IsPList qs, IsFList fs, IsFList gs, Profunctor (PList qs)) => (forall a b. PlainP ps a b -> PlainP qs (PlainF fs a) (PlainF gs b)) -> Square ps qs fs gs -- | A helper function to remove the wrappers needed for PList and -- FList. runSquare :: (IsPList ps, IsPList qs, IsFList fs, IsFList gs, Profunctor (PList qs)) => Square ps qs fs gs -> PlainP ps a b -> PlainP qs (PlainF fs a) (PlainF gs b) -- |
-- +--f--+ +--h--+ +--f--h--+ -- | v | | v | | v v | -- p--@--q ||| q--@--r ==> p--@--@--r -- | v | | v | | v v | -- +--g--+ +--i--+ +--g--i--+ ---- -- Horizontal composition of squares. proId is the identity of -- `(|||)`. This is regular function composition of the underlying -- functions. (|||) :: (Profunctor (PList rs), IsFList fs, IsFList gs, Functor (FList hs), Functor (FList is)) => Square ps qs fs gs -> Square qs rs hs is -> Square ps rs (fs ++ hs) (gs ++ is) infixl 6 ||| -- |
-- +--f--+ -- | v | -- p--@--q +--f--+ -- | v | | v | -- +--g--+ p--@--q -- === ==> | v | -- +--g--+ r--@--s -- | v | | v | -- r--@--s +--h--+ -- | v | -- +--h--+ ---- -- Vertical composition of squares. funId is the identity of -- `(===)`. (===) :: (IsPList ps, IsPList qs, Profunctor (PList ss)) => Square ps qs fs gs -> Square rs ss gs hs -> Square (ps ++ rs) (qs ++ ss) fs hs infixl 5 === -- |
-- +--f--+ -- | v | -- | \->f -- | | -- +-----+ ---- -- A functor f can be bent to the right to become the profunctor -- Star f. toRight :: Functor f => Square '[] '[Star f] '[f] '[] -- |
-- +--f--+ -- | v | -- f<-/ | -- | | -- +-----+ ---- -- A functor f can be bent to the left to become the profunctor -- Costar f. toLeft :: Functor f => Square '[Costar f] '[] '[f] '[] -- |
-- +-----+ -- | | -- | /-<f -- | v | -- +--f--+ ---- -- The profunctor Costar f can be bent down to become the -- functor f again. fromRight :: Functor f => Square '[] '[Costar f] '[] '[f] -- |
-- +-----+ -- | | -- f>-\ | -- | v | -- +--f--+ ---- -- The profunctor Star f can be bent down to become the -- functor f again. fromLeft :: Functor f => Square '[Star f] '[] '[] '[f] -- |
-- +-----+ -- f>-\ | fromLeft -- | v | === -- f<-/ | toLeft -- +-----+ ---- -- fromLeft and toLeft can be composed vertically to bend -- Star f back to Costar f. uLeft :: Functor f => Square '[Star f, Costar f] '[] '[] '[] -- |
-- +-----+ -- | /-<f fromRight -- | v | === -- | \->f toRight -- +-----+ ---- -- fromRight and toRight can be composed vertically to bend -- Costar f to Star f. uRight :: Functor f => Square '[] '[Costar f, Star f] '[] '[] -- |
-- +f-f-f+ +--f--+ spiderLemma n = -- |v v v| f> v <f fromLeft ||| funId ||| fromRight -- | \|/ | | \|/ | === -- p--@--q ==> p--@--q n -- | /|\ | | /|\ | === -- |v v v| g< v >g toLeft ||| funId ||| toRight -- +g-g-g+ +--g--+ ---- -- The spider lemma is an example how bending wires can also be seen as -- sliding functors around corners. spiderLemma :: (Profunctor p, Profunctor q, Functor f1, Functor f2, Functor f3, Functor g1, Functor g2, Functor g3) => Square '[p] '[q] '[f1, f2, f3] '[g1, g2, g3] -> Square '[Star f1, p, Costar g1] '[Costar f3, q, Star g3] '[f2] '[g2] -- |
-- spiderLemma' n = (toRight === proId === fromRight) ||| n ||| (toLeft === proId === fromLeft) ---- -- The spider lemma in the other direction. spiderLemma' :: (Profunctor p, Profunctor q, Functor f1, Functor f2, Functor f3, Functor g1, Functor g2, Functor g3) => Square '[Star f1, p, Costar g1] '[Costar f3, q, Star g3] '[f2] '[g2] -> Square '[p] '[q] '[f1, f2, f3] '[g1, g2, g3] -- |
-- H²-f--H -- | v | -- p--@--q H = Hask, H² = Hask x Hask -- | v | -- H²-g--H --type Square21 ps1 ps2 qs f g = SquareNT (PList ps1 :**: PList ps2) (PList qs) (UncurryF f) (UncurryF g) -- | Combine two profunctors from Hask to a profunctor from Hask x Hask data ( p1 :**: p2 ) a b [:**:] :: p1 a1 b1 -> p2 a2 b2 -> (p1 :**: p2) '(a1, a2) '(b1, b2) -- | Uncurry the kind of a bifunctor. -- --
-- type UncurryF :: (a -> b -> Type) -> (a, b) -> Type --data UncurryF f a [UncurryF] :: {curryF :: f a b} -> UncurryF f '(a, b) -- |
-- 1--a--H -- | v | -- U--@--q 1 = Hask^0 = (), H = Hask -- | v | -- 1--b--H --type Square01 qs a b = SquareNT Unit (PList qs) (ValueF a) (ValueF b) -- | The boring profunctor from and to the unit category. data Unit a b [Unit] :: Unit '() '() -- | Values as a functor from the unit category. data ValueF x u [ValueF] :: a -> ValueF a '() module Data.Traversable.Square -- |
-- +--t--+ -- | v | -- f>-T->f -- | v | -- +--t--+ ---- -- traverse as a square. -- -- Naturality law: -- --
-- +-----t--+ +--t-----+ -- | v | | v | -- f>-@->T->g === f>-T->@->g -- | v | | v | -- +-----t--+ +--t-----+ ---- -- Identity law: -- --
-- +--t--+ +--t--+ -- | v | | | | -- | T | === | v | -- | v | | | | -- +--t--+ +--t--+ ---- -- Composition law: -- --
-- +--t--+ +--t--+ -- | v | | v | -- f>-T->f f>\|/>f -- | v | === | T | -- g>-T->g g>/|\>g -- | v | | v | -- +--t--+ +--t--+ --traverse :: (Traversable t, Applicative f) => Square '[Star f] '[Star f] '[t] '[t] -- |
-- +-f-t---+ -- | v v | -- | \-@-\ | -- | v v | -- +---t-f-+ ---- --
-- sequence = toRight ||| traverse ||| fromLeft --sequence :: (Traversable t, Applicative f) => Square '[] '[] '[f, t] '[t, f] module Data.Profunctor.Square -- |
-- +-a⊗_-+ -- | v | -- p--@--p -- | v | -- +-a⊗_-+ --second :: Strong p => Square '[p] '[p] '[(,) a] '[(,) a] -- |
-- +-a⊕_-+ -- | v | -- p--@--p -- | v | -- +-a⊕_-+ --right :: Choice p => Square '[p] '[p] '[Either a] '[Either a] -- |
-- +-a→_-+ -- | v | -- p--@--p -- | v | -- +-a→_-+ --closed :: Closed p => Square '[p] '[p] '[(->) a] '[(->) a] -- |
-- +--f--+ -- | v | -- p--@--p -- | v | -- +--f--+ --map :: (Mapping p, Functor f) => Square '[p] '[p] '[f] '[f] -- |
-- +-----+ -- | | -- (→)-@ | -- | | -- +-----+ --fromHom :: Square '[(->)] '[] '[] '[] -- |
-- +-----+ -- | | -- | @-(→) -- | | -- +-----+ --toHom :: Square '[] '[(->)] '[] '[] -- |
-- +-----+ -- | /-p -- q.p-@ | -- | \-q -- +-----+ --fromProcompose :: (Profunctor p, Profunctor q) => Square '[Procompose q p] '[p, q] '[] '[] -- |
-- +-----+ -- p-\ | -- | @-q.p -- q-/ | -- +-----+ --toProcompose :: (Profunctor p, Profunctor q) => Square '[p, q] '[Procompose q p] '[] '[] module Data.Functor.Square -- |
-- +--I--+ -- | v | -- | @ | -- | | -- +-----+ --fromIdentity :: Square '[] '[] '[Identity] '[] -- |
-- +-----+ -- | | -- | @ | -- | v | -- +--I--+ --toIdentity :: Square '[] '[] '[] '[Identity] -- |
-- +-g.f-+ -- | v | -- | /@\ | -- | v v | -- +-f-g-+ --fromCompose :: (Functor f, Functor g) => Square '[] '[] '[Compose g f] '[f, g] -- |
-- +-f-g-+ -- | v v | -- | \@/ | -- | v | -- +-g.f-+ --toCompose :: (Functor f, Functor g) => Square '[] '[] '[f, g] '[Compose g f] module Data.Functor.Rep.Square -- |
-- +-k→_-+ -- | v | -- | @ | -- | v | -- +--f--+ --tabulate :: Representable f => Square '[] '[] '[(->) (Rep f)] '[f] -- |
-- +--f--+ -- | v | -- | @ | -- | v | -- +-k→_-+ --index :: Representable f => Square '[] '[] '[f] '[(->) (Rep f)] module Data.Functor.Adjunction.Square -- |
-- +-----+ -- | | -- f<-@->g -- | | -- +-----+ ---- --
-- leftAdjunct = unit === (toLeft ||| toRight) --leftAdjunct :: Adjunction f g => Square '[Costar f] '[Star g] '[] '[] -- |
-- +-----+ -- | | -- g>-@-<f -- | | -- +-----+ ---- --
-- rightAdjunct = (fromLeft ||| fromRight) === counit --rightAdjunct :: Adjunction f g => Square '[Star g] '[Costar f] '[] '[] -- |
-- +-----+ -- | | -- | /@\ | -- | v v | -- +-f-g-+ ---- --
-- unit = fromRight ||| leftAdj ||| fromLeft --unit :: Adjunction f g => Square '[] '[] '[] '[f, g] -- |
-- +-g-f-+ -- | v v | -- | \@/ | -- | | -- +-----+ ---- --
-- counit = toRight ||| rightAdjoint ||| toLeft --counit :: Adjunction f g => Square '[] '[] '[g, f] '[] module Data.Distributive.Square -- |
-- +--t--+ -- | v | -- f<-@-<f -- | v | -- +--t--+ ---- --
-- cotraverse = (funId ||| fromRight) === distribute === (toLeft ||| funId) --cotraverse :: (Distributive t, Functor f) => Square '[Costar f] '[Costar f] '[t] '[t] -- |
-- +---t-f-+ -- | v v | -- | /-@-/ | -- | v v | -- +-f-t---+ ---- --
-- distribute = fromRight ||| cotraverse ||| toLeft --distribute :: (Distributive t, Functor f) => Square '[] '[] '[t, f] '[f, t] module Control.Monad.Square -- |
-- +-----+ -- | | -- | R | -- | v | -- +--m--+ --return :: Monad m => Square '[] '[] '[] '[m] -- |
-- +--m--+ -- | v | -- m>-B | -- | v | -- +--m--+ ---- -- `(>>=)` as a square (or to be precise its flipped version -- `(=<<)`) -- -- Left identity law: -- --
-- +-----+ -- | R | +-----+ -- | v | | | -- m>-B | === m>-\ | -- | v | | v | -- +--m--+ +--m--+ ---- -- Right identity law: -- --
-- +---m-+ -- | R v | +--m--+ -- | v | | | | | -- | \-B | === | v | -- | v | | | | -- +---m-+ +--m--+ ---- -- Associativity law: -- --
-- +--m--+ +---m-+ -- | v | m>\ v | -- m>-B | | v | | -- | v | === m>B | | -- m>-B | | \-B | -- | v | | v | -- +--m--+ +---m-+ --bind :: Monad m => Square '[Star m] '[] '[m] '[m] -- |
-- +-m-m-+ -- | v v | -- | \-@ | -- | v | -- +---m-+ ---- --
-- join = toRight ||| bind --join :: Monad m => Square '[] '[] '[m, m] '[m] -- |
-- +-----+ -- m>-\ | -- m>-@ | -- | \->m -- +-----+ ---- -- Kleisli composition `(M.>=>)` -- --
-- (>=>) = fromLeft === bind === toRight --(>=>) :: Monad m => Square '[Star m, Star m] '[Star m] '[] '[] module Control.Comonad.Square -- |
-- +--w--+ -- | v | -- | X | -- | | -- +-----+ --extract :: Comonad w => Square '[] '[] '[w] '[] -- |
-- +--w--+ -- | v | -- w<-E | -- | v | -- +--w--+ ---- -- extend as a square -- -- Right identity law: -- --
-- +--w--+ -- | v | +--w--+ -- w<-E | | v | -- | v | === w<-/ | -- | X | | | -- +-----+ +-----+ ---- -- Left identity law: -- --
-- +---w-+ -- | v | +--w--+ -- | /-E | | | | -- | v | | === | v | -- | X v | | | | -- +---w-+ +--w--+ ---- -- Associativity law: -- --
-- +--w--+ +---w-+ -- | v | | v | -- w<-E | | /-E | -- | v | === w<E | | -- w<-E | | | | | -- | v | w</ v | -- +--w--+ +---w-+ --extend :: Comonad w => Square '[Costar w] '[] '[w] '[w] -- |
-- +---w-+ -- | v | -- | /-@ | -- | v v | -- +-w-w-+ ---- --
-- duplicate = fromRight ||| extend --duplicate :: Comonad w => Square '[] '[] '[w] '[w, w] -- |
-- +-----+ -- | /-<w -- w<-@ | -- w<-/ | -- +-----+ ---- -- Cokleisli composition `(W.<=<)` -- --
-- (<=<) = fromRight === extend === toLeft --(<=<) :: Comonad w => Square '[Costar w, Costar w] '[Costar w] '[] '[] module Control.Arrow.Square -- |
-- +-----+ -- | | -- | @--a -- | | -- +-----+ --arr :: (Arrow a, Profunctor a) => Square '[] '[a] '[] '[] -- |
-- +-----+ -- a--\ | -- | @--a -- a--/ | -- +-----+ --(>>>) :: (Arrow a, Profunctor a) => Square '[a, a] '[a] '[] '[] -- |
-- +-_⊗d-+ -- | v | -- a--@--a -- | v | -- +-_⊗d-+ --second :: (Arrow a, Profunctor a) => Square '[a] '[a] '[(,) d] '[(,) d] -- |
-- H²-⊗--H -- | v | -- a²-@--a -- | v | -- H²-⊗--H --(***) :: Arrow a => Square21 '[a] '[a] '[a] (,) (,) -- |
-- +-_⊕d-+ -- | v | -- a--@--a -- | v | -- +-_⊕d-+ --right :: (ArrowChoice a, Profunctor a) => Square '[a] '[a] '[Either d] '[Either d] -- |
-- H²-⊕--H -- | v | -- a²-@--a -- | v | -- H²-⊕--H --(+++) :: ArrowChoice a => Square21 '[a] '[a] '[a] Either Either module Data.Foldable.Square -- |
-- +--f--+ -- | v | -- !m-@-!m -- | ? | -- +--?--+ ---- -- foldMap as a square. Note that because Forget ignores -- its output parameter, this square can have any list of functors as -- output type. foldMap :: (Foldable f, Monoid m, IsFList gs) => Square '[Forget m] '[Forget m] '[f] gs