Products and Coproducts
Prev: Kleisli Categories Next: Simple Algebraic Data Types
Prev: Kleisli Categories Next: Simple Algebraic Data Types
Exercises
- Show that the terminal object is unique up to unique isomorphism.
- What is a product of two objects in a poset? Hint: Use the universal construction.
- What is a coproduct of two objects in a poset?
- Implement the equivalent of Haskell
Eitheras a generic type in your favorite language (other than Haskell). - Show that
Eitheris a “better” coproduct thanintequipped with two injections:
int i(int n) { return n; }
int j(bool b) { return b ? 0: 1; }Hint: Define a function
int m(Either const & e);that factorizes i and j.
- Continuing the previous problem: How would you argue that
intwith the two injectionsiandjcannot be “better” thanEither? - Still continuing: What about these injections?
int i(int n) {
if (n < 0) return n;
return n + 2;
}
int j(bool b) { return b ? 0: 1; }- Come up with an inferior candidate for a coproduct of
intandboolthat cannot be better thanEitherbecause it allows multiple acceptable morphisms from it toEither.