Irrefut patterns refactoring

Various refactorings and bug fixes that I did as part of a branch to fix irrefutable let pattern bindings.

r? @catamorphism