2.1 What Are Types?
Types can be seen as sets of values. Bool for example can be seen as a two-element set of True and False
Sets can be finite or infinite. Bool is obviously finite. Integer is infinite.
Okay, cool. Here’s something cooler: There is a category of sets called Set. In Set, objects are sets and morphism are… functions!
So, you can kind of see programming as turning objects in category Set using morphisms!
Okay, but it gets trickier. A function in programming may or may not give back an answer. A function that may return nothing is called a partial function, while one that always return something is called a total function.
A return of nothing is also called a bottom. Haskell types may return a bottom and it’s usually referred as Hask instead of Set.
2.2 Pure And Dirty Functions
In programming, function usually have side effects, which is usually any interaction with mutable global states of some sort. Function that no have side effects ensures that it will affect nothing outside of the function.
A function that always produces the same output given the same input and produces no side effects is called a pure function. Anything else is a dirty function.
2.3 Examples of Types
If types are sets, then what’s the equivalent of empty sets? In Haskell it’s Void (not to be confused with C/C++ void which is super different). Void in Haskell is uncallable. A function that takes a Void is called an absurd and it can’t be called.
What about single element sets? In Haskell it can be presented as (), and a function that takes this as an argument does actually kind of acts like void in C/C++.