3.6 type inference
How does Haskell know which types are being used in places? Equivalently, why does this make our life so much easier?
The algorithm for this is relatively straightforward:
- Assign type variables for each name in an expression
- A name here is a function, variable passed into said function, etc.
- Then, apply these to each other to build relations based on the order of the expression.
- Use equality to then build up the final type for the function.
Check the notes to see an example of this. Also, the series on Jeremy's Blog gladly explains it in much more depth, so it isn't copied here right now as the notes don't seem to feel the need to go into greater depth.