Part 2: I Wanna Be FAMIOus!
Let us recap our high-level Hask picture so far. We have values grouped together in types, such as Char or Int. We have functions: mapping of one, or several, values of one type to one and only one value of a type. Such as length :: String -> Int or fact :: Int -> Int. Functions are values, too - you can pass them to a function and define types consisting of functions as values. We have type functions or parametric types - they take a whole type as a value and construct a different type out of it. Such as a list type [a] or Maybe a, where variable a can be of any concrete type. We have polymorphic functions - those that are defined on parametric types and work regardless of what exact type a is. Such as length :: [a] -> Int or map :: (a -> b) -> [a] -> [b].
The real power (and complexity) of Haskell comes from various abstractions, like polymorphic functions we looked at in the last chapter. The next such mechanism is Typeclasses.
What is a typeclass? If you read the “Type Theory intro” chapter, you already know that typeclasses, multiparameter typeclasses, as well as type and data families are all simply cases of \(\sum\)-types. In essence, they take a type (or several in case of multiparameter typeclasses) and add some structure to the type (or between types for multiparameter typeclasses). In the next few chapters, we will look at different kinds of important typeclasses using ubiquitous Haskell examples and try to show their increasing power of abstraction.