solution

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

Solution 9.3.1

proof — Exercise 9.3.1

, using naturality of then . See Natural Transformation.

Sources: DaoFP Exercise 9.3.1.

Solution 9.3.2

program — Exercise 9.3.2

safeHead . fmap reverse and fmap reverse . safeHead, both of type [[a]] -> Maybe [a]; e.g. on [[1,2],[3]] both give Just [2,1], on [] both give Nothing. Equal by naturality of safeHead.

Sources: DaoFP Exercise 9.3.2.

Solution 9.3.3

program — Exercise 9.3.3

Both send [[1,2],[],[3]] to [Just 3, Nothing, Just 1]; equal by naturality of reverse.

Sources: DaoFP Exercise 9.3.3.

Solution 9.5.1

Exercise 9.5.1

A cone with apex is , with , so it is determined by : with legs and . Elements are elements of .

Sources: DaoFP Exercise 9.5.1.

Solution 9.5.2

program — Exercise 9.5.2

q' x is True iff x is odd; h q' (q x) returns q' 0 = False when x is even and q' 1 = True when odd. Equal for all x. See Coequalizer.

Sources: DaoFP Exercise 9.5.2.

Solution 9.6.1

Exercise 9.6.1

If there are no natural transformations either: would have to send somewhere. Both sides are empty, so the bijection holds. See Yoneda Lemma.

Sources: DaoFP Exercise 9.6.1.

Solution 9.6.2

proof — Exercise 9.6.2

For and : by functoriality of ; that is .

Sources: DaoFP Exercise 9.6.2.

Solution 9.6.3

proof — Exercise 9.6.3

Naturality for applied to : , i.e. since is post-composition.

Sources: DaoFP Exercise 9.6.3.

Solution 9.8.1

Exercise 9.8.1

represents the presheaf (cones with apex ); represents the co-presheaf (cocones).

Sources: DaoFP Exercise 9.8.1.

Solution 9.8.2

proof — Exercise 9.8.2

means each is a singleton, i.e. is initial; conversely if is initial, naturally.

Sources: DaoFP Exercise 9.8.2.

Solution 9.8.3

program — Exercise 9.8.3

instance Representable Pair where
  type Key Pair = Bool
  tabulate g = Pair (g True) (g False)
  index (Pair a b) = \k -> if k then a else b

; see Representable Functor.

Sources: DaoFP Exercise 9.8.3.

Solution 9.8.4

program — Exercise 9.8.4

Yes, by the Initial Object (Void): — “the logarithm of 1 is 0”.

instance Representable Unit where
  type Key Unit = Void
  tabulate _ = U
  index U = absurd

Sources: DaoFP Exercise 9.8.4.

Solution 9.8.5

Exercise 9.8.5

Yes: , a coproduct of the representables , one for each length. See Representable Functor, Free Monoid.

Sources: DaoFP Exercise 9.8.5.