Challenge 6 from section 2.7 of the CTFP book

38 Views Asked by At

I am reading the nice Category Theory for Programmers book from Bartosz Milewski (https://github.com/hmemcpy/milewski-ctfp-pdf/). I would like to check my solutions to exercises, but I did not find anything online on Challenge 6 of section 2.7. I am copying the exercise here:

Draw a picture of a category whose only objects are the types Void, () (unit), and Bool; with arrows corresponding to all possible functions between these types.

In case the notation is not clear (I'm not sure how much of it is specific to Haskell or this book, vs. standard math notation), here are some definitions taken from the book:

  • Void is the empty set.
  • () or unit denotes a singleton set.
  • Bool denotes a set with two elements.

Also, type can be taken as equivalent to a mathematical set.

Here is my solution:

enter image description here

Is it correct? In particular, I'm confused about Void. Should we allow functions that return Void?

1

There are 1 best solutions below

0
On BEST ANSWER

It’s mostly correct. But, as you already suspected, there are no functions from other types to Void, since every element has to be mapped to something, and there’s nothing to map it to in the void. Your arrow from Void to Void is right, though, since the void domain doesn’t contain any elements that would have to be mapped to the non-existent elements of the void co-domain.

Also, there should be only one arrow from Void to Bool, as there’s only one way not to map any elements to Bool.

The general expression for the number of functions from $X$ to $Y$ is $|Y|^{|X|}$, since there are $|X|$ function values to choose, with $|Y|$ choices in each case. (Here $0^0$ needs to be defined as $1$ to make the expression work for functions from Void to Void.)