You may have heard that Functional Programming (FP) uses concepts of the category theory and type theory. This link is the reason why some people find FP closer to mathematics. Theoretically, category refers to a collection that contains the following:
- A collection of objects (types in Swift)
- A collection of morphisms, each of which ties two objects together (functions in Swift)
- A notion of composition of the morphisms (function composition in Swift)
We have already discussed functions and function composition and now we are going to explore types.
It is possible to categorize types in four different ways:
- Named versus compound types
- Sum versus product types
- Abstract versus concrete types
- Value versus reference types
Any type that we can give a name to while we define it, is a named type. For instance, if we create a class named OurClass, any instance of OurClass will be of the OurClass type.
...