n      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\ ] ^ _ ` a b c d e f g h i j k l m GADTs, MPTCs, fundeps provisionalEdward Kmett <ekmett@gmail.com> Trustworthy%A form suitable for Yoneda reduction Yoneda  expansion     .  "a n   .  "a n    o =  Yoneda reduction   p =  =  Yoneda reduction given a q.   p =  =  'rstuvwxyz{|}~&rstuvwxyz{|}~MPTCs, fundeps provisionalEdward Kmett <ekmett@gmail.com> Trustworthy-   +  rank N types experimentalEdward Kmett <ekmett@gmail.com> Trustworthy  g .  g f => fLThis could alternately be defined directly from the (co)universal propertly  in which case, we'd get  =  UniversalRift, but then the usage would  suffer.    data  UniversalRift g f a = forall z.  z =>   UniversalRift" (forall x. g (z x) -> f x) (z a) EWe can witness the isomorphism between Rift and UniversalRift using:   < riftIso1 :: Functor g => UniversalRift g f a -> Rift g f a ' riftIso1 (UniversalRift h z) = Rift $ g -> h $ fmap (k -> k  $ z) g   / riftIso2 :: Rift g f a -> UniversalRift g f a ( riftIso2 (Rift e) = UniversalRift e id    riftIso1 (riftIso2 (Rift h)) = ; riftIso1 (UniversalRift h id) = -- by definition  Rift $ g -> h $ fmap (k -> k  $ id) g -- by definition  Rift $ g# -> h $ fmap id g --  $ = (.) and (.id)  Rift $ g2 -> h g -- by functor law ; Rift h -- eta reduction ;The other direction is left as an exercise for the reader. /There are several monads that we can form from Rift. When g@ is corepresentable (e.g. is a right adjoint) then there exists x such that  g ~ (->) x, then it follows that    Rift g g a ~ % forall r. (x -> a -> r) -> x -> r ~ % forall r. (a -> x -> r) -> x -> r ~  forall r. (a -> g r) -> g r ~  Codensity g r When f is a left adjoint, so that f -| g then    Rift f f a ~  forall r. f (a -> r) -> f r ~ ! forall r. (a -> r) -> g (f r) ~ ' forall r. (a -> r) -> Adjoint f g r ~  Yoneda (Adjoint f g r) 9An alternative way to view that is to note that whenever f is a left adjoint then f -|  f  , and since  f f is isomorphic to  f  (f a), this is the q formed by the adjunction.  w f ~   w f can be a q for any Comonad w.   m can be a q for any q m, as it is isomorphic to Yoneda m. 4Indexed applicative composition of right Kan lifts. The universal property of  When f -| u, then f -| Rift f Identity and    .  "a n   .  "a n Rift f Identity a' is isomorphic to the right adjoint to f if one exists.    .  "a n   .  "a n Rift f Identity a' is isomorphic to the right adjoint to f if one exists.     .  "a n   .  "a n  Rift f h a? is isomorphic to the post-composition of the right adjoint of f onto h! if such a right adjoint exists.    .  "a n   .  "a n  Rift f h a? is isomorphic to the post-composition of the right adjoint of f onto h! if such a right adjoint exists.    rank N types experimentalEdward Kmett <ekmett@gmail.com> Trustworthy   f => g . Lift g f 8 (forall z. f => g . z) -> Lift g f => z -- couniversal UHere we use the universal property directly as how we extract from our definition of .  f => g ( g f a)The universal property of  When the adjunction exists     .  "a n   .   "a n !   ! . " = n  " . ! = n #Lift u Identity a& is isomorphic to the left adjoint to u if one exists.   # . $ "a n  $ . # "a n $Lift u Identity a& is isomorphic to the left adjoint to u if one exists. %   % . & "a n  & . % "a n ' Lift u h a> is isomorphic to the post-composition of the left adjoint of u onto h if such a left adjoint exists.   ' . ( "a n  ( . ' "a n ( Lift u h a> is isomorphic to the post-composition of the left adjoint of u onto h if such a left adjoint exists. )   ) . * "a n  * . ) "a n  !"#$%&'()* !"#$%&'()* !"#$'(%&)* !"#$%&'()*GADTs, TFs, MPTCs provisionalEdward Kmett <ekmett@gmail.com> Trustworthy+A 7 functor (aka presheaf) suitable for Yoneda reduction. -Yoneda  expansion of a presheaf .Yoneda reduction on a presheaf +,-.+,-.+,-.+,-. rank 2 types experimentalEdward Kmett <ekmett@gmail.com> Trustworthy/The right Kan extension of a  h along a  g. dWe can define a right Kan extension in several ways. The definition here is obtained by reading off k the definition in of a right Kan extension in terms of an End, but we can derive an equivalent definition  from the universal property. Given a   h : C -> D and a   g : C -> C', we want to find extend h back along g  to give  Ran g h : C' -> C', such that the natural transformation : :: Ran g h (g a) -> h a exists. ;In some sense this is trying to approximate the inverse of g by using one of N its adjoints, because if the adjoint and the inverse both exist, they match!   Hask -h-> Hask  | +  g /  | Ran g h  v /  Hask -' `The Right Kan extension is unique (up to isomorphism) by taking this as its universal property. That is to say given any K : C' -> C1 such that we have a natural transformation from k.g to h  (forall x. k (g x) -> h x)6 there exists a canonical natural transformation from k to Ran g h.  (forall x. k x -> Ran g h x). BWe could literally read this off as a valid Rank-3 definition for /:    data Ran' g h a = forall z.  z => Ran'" (forall x. z (g x) -> h x) (z a) ]This definition is isomorphic the simpler Rank-2 definition we use below as witnessed by the    ranIso1 :: Ran g f x -> Ran' g f x  ranIso1 (Ran e) = Ran' e id  ranIso2 :: Ran' g f x -> Ran g f x  ranIso2 (Ran' h z) = Ran $ k -> h (k  $ z)   . ranIso2 (ranIso1 (Ran e)) "a -- by definition  ranIso2 (Ran' e id) "a -- by definition  Ran $ k -> e (k  $ id) -- by definition  Ran $ k" -> e (k . id) -- f . id = f  Ran $ k% -> e k -- eta reduction  Ran e ;The other direction is left as an exercise for the reader. 21The universal property of a right Kan extension. 32 and 3* witness a higher kinded adjunction. from ( `'Compose'` g) to / g   2 . 3 "a n  3 . 2 "a n 4   4 . 5 "a n  5 . 4 "a n 6   6 . 7 "a n  7 . 6 "a n 8   9 . 8 "a n  8 . 9 "a n :GThis is the natural transformation that defines a Right Kan extension. /0123456789:;<=>/0123456789:;<=>/0123:456798;<>=/0123456789:;<=>"non-portable (rank-2 polymorphism) provisionalEdward Kmett <ekmett@gmail.com> Trustworthy?? f: is the Monad generated by taking the right Kan extension  of any  f along itself (Ran f f). This can often be more " efficient" to construct than f itself using  repeated applications of (>>=). See "7Asymptotic Improvement of Computations over Free Monads" by Janis 4 Voightlnder for more information about this type.  (http://www.iai.uni-bonn.de/~jv/mpc08.pdf B2This serves as the *left*-inverse (retraction) of o.    'lowerCodensity . lift' "a n GIn general this is not a full 2-sided inverse, merely a retraction, as  ? m is often considerably larger than m. e.g. ?0 ((->) s)) a ~ forall r. (a -> s -> r) -> s -> r $ could support a full complement of  s actions, while (->) s  is limited to  s actions. CThe ?/ monad of a right adjoint is isomorphic to the  monad obtained from the .   C . D "a n  D . C "a n EThe ? monad of a representable  is isomorphic to the  monad obtained from the  for which that  is the right  adjoint.    E . F "a n  F . E "a n    codensityToComposedRep = = . G F   F = H . > GThe ? q of a  g is the right Kan extension (/)  of g along itself.   G . H "a n  H . G "a n IGRight associate all binds in a computation that generates a free monad KThis can improve the asymptotic efficiency of the result, while preserving  semantics. See "7Asymptotic Improvement of Computations over Free Monads" by Janis : Voightlnder for more information about this combinator.  (http://www.iai.uni-bonn.de/~jv/mpc08.pdf ?@ABCDEFGHI ?@ABCDEFGHI ?@ABCDGHEFI?@ABCDEFGHI"non-portable (rank-2 polymorphism) provisionalEdward Kmett <ekmett@gmail.com> TrustworthyJ   J w m a ~    w m a  M w a ~    w  a JKLMNOPQRSTUVWXYZ[JKLMNOPQRSTUVWXYZ[MNOJKLPQRSTUVWXYZ[JKLMNOPQRSTUVWXYZ[  rank 2 types experimentalEdward Kmett <ekmett@gmail.com> Trustworthy\The left Kan extension of a  h along a  g. ^0The universal property of a left Kan extension. __ and ^. witness a (higher kinded) adjunction between \ g and (Compose g)   ^ . _ "a n  _ . ^ "a n `   ` . a "a n  a . ` "a n bb and c) witness the natural isomorphism between Lan f h and  Compose h g given f -| g   c . b "a n  b . c "a n dd and e& witness the natural isomorphism from Lan f (Lan g h) and Lan (f o g) h   d . e "a n  e . d "a n fFThis is the natural transformation that defines a Left Kan extension. \]^_`abcdef \]^_`abcdef \]^_fde`acb \]^_`abcdef non-portable (GADTs, MPTCs) experimentalEdward Kmett <ekmett@gmail.com> Trustworthyi"The natural transformation from a  w to the  generated by w (forwards). ,This is merely a right-inverse (section) of p, rather than a full inverse.   p . i "a n j The Density ( of a left adjoint is isomorphic to the  formed by that . !This isomorphism is witnessed by j and k.   j . k "a n  k . j "a n lThe g  of a  f. is obtained by taking the left Kan extension  (\) of f0 along itself. This isomorphism is witnessed by l and m   l . m "a n  m . l "a n  ghijklmghijklmghijkml ghijklm   !""#$%&'()*+,-./01123456789:;<=>?@@ABCDEFGHI  JKLMNOPQRSTUVWXY Z Z [ \ ] ^ _ ` a b c d d e f g h ijklmnopqrjkstuvwxyz{|}~uvwxtyz|{}~jkmt  kan-extensions-3.6Data.Functor.Yoneda.ReductionData.Functor.YonedaData.Functor.Kan.RiftData.Functor.Kan.Lift+Data.Functor.Contravariant.Yoneda.ReductionData.Functor.Kan.RanControl.Monad.CodensityControl.Monad.CoData.Functor.Kan.LanControl.Comonad.DensityCoTData.Functor.KanLiftRiftYoneda liftYoneda lowerYonedalowerM runYonedamaxFminFmaxMminMrunRiftrapgrifttoRiftfromRift adjointToRift riftToAdjoint composeRift decomposeRiftriftToComposedAdjointcomposedAdjointToRiftLiftrunLiftglifttoLiftfromLift composeLift decomposeLift adjointToLift liftToAdjoint repToLift liftToRepliftToComposedAdjointcomposedAdjointToLiftliftToComposedRepcomposedRepToLiftRanrunRantoRanfromRan composeRan decomposeRan adjointToRan ranToAdjointranToComposedAdjointcomposedAdjointToRangranrepToRanranToRepranToComposedRepcomposedRepToRan Codensity runCodensitylowerCodensitycodensityToAdjunctionadjunctionToCodensitycodensityToComposedRepcomposedRepToCodensitycodensityToRanranToCodensityimproverunCoTCocorunColiftCoT0 lowerCoT0lowerCo0liftCoT1 lowerCoT1lowerCo1posWpeekWpeeksWaskWasksWtraceWLantoLanfromLan adjointToLan lanToAdjointlanToComposedAdjointcomposedAdjointToLan composeLan decomposeLanglanDensity liftDensitydensityToAdjunctionadjunctionToDensity lanToDensity densityToLanbaseGHC.Baseidtransformers-0.3.0.0Control.Monad.Trans.Classliftcomonad-transformers-3.0.4Control.Comonad.Trans.ClasslowerMonad$fAdjunctionYonedaYoneda $fOrdYoneda $fEqYoneda $fReadYoneda $fShowYoneda$fDistributiveYoneda$fTraversableWithKey1Yoneda$fTraversableWithKeyYoneda$fTraversable1Yoneda$fTraversableYoneda$fFoldableWithKey1Yoneda$fFoldable1Yoneda$fFoldableWithKeyYoneda$fFoldableYoneda$fComonadTransYoneda$fComonadYoneda$fExtendYoneda$fRepresentableYoneda$fIndexableYoneda$fLookupYoneda$fMonadPlusYoneda$fMonadFixYoneda$fMonadTransYoneda $fMonadYoneda $fBindYoneda $fPlusYoneda $fAltYoneda$fAlternativeYoneda$fZipWithKeyYoneda $fZipYoneda$fApplicativeYoneda $fApplyYoneda $fKeyedYoneda$fFunctorYoneda$fMonadFreefYoneda$fMonadSpecYonedaFunctorData.Functor.IdentityIdentity$fApplicativeRift $fPointedRift $fFunctorRift$fCopointedLift $fFunctorLiftcontravariant-0.4.3Data.Functor.Contravariant Contravariant$fCoindexedYoneda$fValuedYoneda$fContravariantYoneda $fFunctorRan mtl-2.1.2Control.Monad.State.Class MonadStateControl.Monad.Reader.Class MonadReaderadjunctions-3.2.1Data.Functor.Adjunction Adjunction$fMonadStaterCodensity$fMonadFreefCodensity$fMonadPlusCodensity$fAlternativeCodensity$fPlusCodensity$fAltCodensity$fMonadTransCodensity$fMonadIOCodensity$fMonadCodensity$fApplicativeCodensity$fApplyCodensity$fFunctorCodensity$fMonadSpecCodensity$fMonadErroreCoT$fMonadWritereCoT$fMonadStatesCoT$fMonadReadereCoT $fMonadIOCoT$fMonadTransCoT $fMonadCoT$fApplicativeCoT $fBindCoT $fApplyCoT $fFunctorCoT$fMonadSpecCoT$fApplicativeLan $fApplyLan $fFunctorLan comonad-3.1Control.ComonadComonad$fApplicativeDensity$fApplyDensity$fComonadTransDensity$fComonadDensity$fExtendDensity$fFunctorDensity