solution

Solutions to the exercises of DaoFP, Chapter 17: DaoFP Chapter 17 Exercises. Index: Map of Content.

Solution 17.1.1

proof — Exercise 17.1.1

Send every object of to and every object of to ; send morphisms of to , morphisms of to , and heteromorphisms (elements of ) to the unique arrow . Composition is preserved: composing a heteromorphism with a - or -morphism is again a heteromorphism, mapped to ; there are no composable pairs of heteromorphisms since none go from to .

Sources: DaoFP Exercise 17.1.1.

Solution 17.1.2

proof — Exercise 17.1.2

Let and be the full subcategories on the objects sent to and . Since has no arrow , there are no morphisms from -objects to -objects. Define ; it is a Profunctor by pre- and post-composition. Then is exactly the collage of : objects the disjoint union, hom-sets as in , , or , and composition inherited from .

Sources: DaoFP Exercise 17.1.2.

Solution 17.2.1

proof — Exercise 17.2.1

With constant, for all and . The first diamond, for , reads on — exactly the cowedge condition. The second diamond, for , reads , trivially true (the components do not depend on the second index).

Sources: DaoFP Exercise 17.2.1.

Solution 17.2.2

program — Exercise 17.2.2

newtype ProPair q p a b x y = ProPair (q a y, p x b)
instance (Profunctor p, Profunctor q) => Profunctor (ProPair q p a b) where
  dimap f g (ProPair (qay, pxb)) = ProPair (dimap id g qay, dimap f id pxb)

x is contravariant (it is the source of p x b), y covariant (the target of q a y).

Sources: DaoFP Exercise 17.2.2.

Solution 17.2.3

program — Exercise 17.2.3

newtype CoEndCompose p q a b = CoEndCompose (Coend (ProPair q p a b))
instance (Profunctor p, Profunctor q) => Profunctor (CoEndCompose p q) where
  dimap l r (CoEndCompose (Coend (ProPair (qax, pxb)))) =
    CoEndCompose (Coend (ProPair (dimap l id qax, dimap id r pxb)))

Extending on the left acts on q, extending on the right on p; the hidden middle type x is untouched — the same as for Procompose.

Sources: DaoFP Exercise 17.2.3.

Solution 17.3.1

proof — Exercise 17.3.1

Let pick , and . A wedge is an object with , ; since has only identity arrows the wedge condition is vacuous. The universal wedge is therefore an object with two projections through which every such pair factors uniquely — the product . So .

Sources: DaoFP Exercise 17.3.1.

Solution 17.6.1

proof — Exercise 17.6.1

For an arbitrary set : . The functor is covariant (contravariant twice), so the covariant ninja Yoneda lemma gives . By the Yoneda corollary (objects with isomorphic mapping-outs are isomorphic), .

Sources: DaoFP Exercise 17.6.1.

Solution 17.7.1

program — Exercise 17.7.1

instance Functor (Day f g) where
  fmap h (Day abx fa gb) = Day (h . abx) fa gb

Sources: DaoFP Exercise 17.7.1.

Solution 17.7.2

program — Exercise 17.7.2

assoc :: Day f (Day g h) x -> Day (Day f g) h x
assoc (Day abx fa (Day cdb gc hd)) =
  Day (\((a, c), d) -> abx (a, cdb (c, d))) (Day (,) fa gc) hd

The new inner existential type is the pair (a, c); the combining function re-associates.

Sources: DaoFP Exercise 17.7.2.

Solution 17.7.3

program — Exercise 17.7.3

instance Functor f => Functor (FreeA f) where
  fmap h (DoneA x)          = DoneA (h x)
  fmap h (MoreA abx fa frb) = MoreA (h . abx) fa frb

Only the combining function at the head changes; the tail is untouched.

Sources: DaoFP Exercise 17.7.3.

Solution 17.9.1

proof — Exercise 17.9.1

Given and , map : the first factor is covariant in (post-composition), the second contravariant in (pre-composition). Functoriality follows from that of composition and of . So it is a functor in with fixed, and its coend is the existential lens.

Sources: DaoFP Exercise 17.9.1.