Superior type inference

There are some long commit messages - I refer you to those. Review by @retronym, @adriaanm.