Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Stop pretending studying arrow theory improves your apping

Name: Anonymous 2015-03-11 7:12

Given two functors S,T:C→B, a natural transformation τ:S→T is a function which assigns to each object c of C an arrow τc=τc:Sc→TC of B in such a way that every arrow f:c→c' in C yields a diagram
ᅠᅠᅠᅠᅠᅠᅠᅠᅠᅠᅠτc
c ᅠᅠ Sc---→Tc
|ᅠᅠᅠᅠᅠᅠᅠᅠ|ᅠᅠᅠᅠᅠᅠᅠ|
|fᅠᅠᅠᅠᅠSf↓ᅠᅠᅠᅠᅠ↓Tf
↓ᅠᅠᅠᅠᅠᅠᅠ|ᅠᅠτc'ᅠᅠ|
c', ᅠᅠᅠ Sc'--→Tc'


which is commutative. When this holds, we also say that τc=τc:Sc→Tc is natural in c. If we think of the functor S as giving a picture in B of (all the objects and arrows of) C, then a natural transformation τ is the set of arrows mapping (or, translating) the picture S to the picture T, with all squares (and parallelograms!) like that above commutative:
ᅠaᅠᅠᅠᅠᅠᅠᅠᅠᅠᅠSa----------→Ta
ᅠ|ᅠ╲fᅠᅠᅠᅠᅠᅠᅠ ᅠ|ᅠ╲Sfᅠᅠᅠᅠᅠᅠᅠᅠᅠ|ᅠ╲Tf
ᅠ|ᅠᅠᅠ↘ᅠᅠᅠᅠᅠᅠᅠ|ᅠᅠᅠ↘ᅠᅠᅠτbᅠᅠᅠ|ᅠᅠᅠ↘
ᅠ|ᅠᅠᅠᅠᅠbᅠᅠᅠᅠ ᅠ|ᅠᅠᅠᅠSb----------→Tb
ᅠ|ᅠᅠᅠ╱ᅠᅠᅠᅠᅠᅠᅠ|ᅠᅠᅠ╱ᅠᅠᅠᅠᅠᅠᅠᅠᅠ|ᅠᅠᅠ╱
↓ᅠ↙ᅠᅠᅠᅠᅠᅠ ᅠ↓↙Sgᅠᅠᅠᅠᅠᅠᅠᅠ↓ᅠ↙Tg
ᅠcᅠᅠᅠᅠᅠᅠᅠᅠᅠᅠSc----------→Tc

Name: Anonymous 2015-03-12 15:10

-- | "Fuse" a 'Traversal' by reassociating all of the '<*>' operations to the
-- left and fusing all of the 'fmap' calls into one. This is particularly
-- useful when constructing a 'Traversal' using operations from GHC.Generics.
--
-- Given a pair of 'Traversal's 'foo' and 'bar',
--
-- @
-- 'confusing' (foo.bar) = foo.bar
-- @
--
-- However, @foo@ and @bar@ are each going to use the 'Applicative' they are given.
--
-- 'confusing' exploits the 'Yoneda' lemma to merge their separate uses of 'fmap' into a single 'fmap'.
-- and it further exploits an interesting property of the right Kan lift (or 'Rift') to left associate
-- all of the uses of '(<*>)' to make it possible to fuse together more fmaps.
--
-- This is particularly effective when the choice of functor 'f' is unknown at compile
-- time or when the 'Traversal' @foo.bar@ in the above description is recursive or complex
-- enough to prevent inlining.
--
-- 'Control.Lens.Lens.fusing' is a version of this combinator suitable for fusing lenses.
--
-- @
-- 'confusing' :: 'Traversal' s t a b -> 'Traversal' s t a b
-- @
confusing :: Applicative f => LensLike (Rift (Yoneda f) (Yoneda f)) s t a b -> LensLike f s t a b
confusing t = \f -> lowerYoneda . lowerRift . t (liftRiftYoneda . f)
where
liftRiftYoneda :: Applicative f => f a -> Rift (Yoneda f) (Yoneda f) a
liftRiftYoneda fa = Rift (`yap` fa)
{-# INLINE liftRiftYoneda #-}

yap :: Applicative f => Yoneda f (a -> b) -> f a -> Yoneda f b
yap (Yoneda k) fa = Yoneda (\ab_r -> k (ab_r .) <*> fa)
{-# INLINE yap #-}

{-# INLINE confusing #-}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List